[Python-Dev] Interning string subtype instances

Larry Hastings larry at hastings.org
Wed Feb 14 20:27:59 CET 2007


Greg Ewing wrote:
> Can anyone shed any light on this? It seems to me that
> by not using this information, only half the benefit of
> interning is being achieved.
If I understand your question correctly, you're saying "why doesn't 
string comparison take advantage of interned strings?"  If so, the 
answer is "it does".  Examine string_richcompare() in stringobject.c, 
and PyUnicode_compare() in unicodeobject.c.  Both functions compare the 
pointers of the two objects in case they are literally the same object, 
and if so skip all the expensive comparison code.  Interned strings 
which have the same value are likely to be (are guaranteed to be?) the 
same object.  And there you are.

If that's not the question you are asking, I'll be quiet, 'cause it 
seems like other people understand what you're talking about.

Cheers,


/larry/


More information about the Python-Dev mailing list