[Python-Dev] Interning string subtype instances

Josiah Carlson jcarlson at uci.edu
Mon Feb 12 21:29:37 CET 2007


Hrvoje Nikšic <hrvoje.niksic at avl.com> wrote:
> 
> I propose modifying PyString_InternInPlace to better cope with string
> subtype instances.

Any particular reason why the following won't work for you?

_interned = {}

def intern(st):
    #add optional type checking here
    if st not in _interned:
        _interned[st] = st
    return _interned[st]

If I remember the implementation of intern correctly, that's more or
less what happens under the covers.

 - Josiah



More information about the Python-Dev mailing list