[Python-Dev] Alternative implementation of interning, take 2

Oren Tirosh oren-py-d@hishome.net
Fri, 12 Jul 2002 07:15:03 -0400


On Fri, Jul 12, 2002 at 10:24:10AM +0200, M.-A. Lemburg wrote:
> >It would help if you could get Marc-Andre and /F to pronounce on whether
> >their code benefits from it -- they're the most prolific extension authors
> >we've got.
> 
> Gee, thanks :-)
> 
> If you could spell out what exactly you mean by "indirect interning"
> that would help.

That's how I call a string whose ob_sinterned is not NULL but doesn't point 
to itself, either.  Such strings are relatively rare. In order to create
one you need to call PyString_InternInPlace on a string that has more than
one reference. The pointer used for the interning is replaced with a "true"
interned string (i.e s->ob_sinterned == s).  The other references still
point to the original string which is now "indirectly interned".

Indirectly interned strings can't be used to speed up comparisons using
'is' instead of '=='.  Using them as dictionary keys does save an strcmp,
though. If I understand this correctly they are used as an optimization for 
extension modules that use PyString_FromString instead of 
PyString_InternFromString for their string constants using a hack in 
PyDict_SetItem that interns the key it gets. 

	Oren