[Python-Dev] Interning string subtype instances (original) (raw)
Hrvoje Nikšić hrvoje.niksic at avl.com
Tue Feb 13 09:46:40 CET 2007
- Previous message: [Python-Dev] Interning string subtype instances
- Next message: [Python-Dev] Interning string subtype instances
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, 2007-02-12 at 12:29 -0800, Josiah Carlson wrote:
Hrvoje Nikšic <hrvoje.niksic at avl.com> wrote: > > I propose modifying PyStringInternInPlace to better cope with string > subtype instances.
Any particular reason why the following won't work for you? [... snipped a simple intern implementation ...]
Because Python internals don't use that; they call PyString_InternInPlace directly.
Another reason is that Python's interning mechanism is much better than such a simple implementation: it stores the interned state directly in the PyString_Object structure, so you can find out that a string is already interned without looking it up in the dictionary. This information can (and is) used by both Python core and by C extensions. Another advantage is that, as of recently, interned strings can be garbage collected, which is typically not true of simple replacements (although it could probably be emulated by using weak references, it's not trivial.)
- Previous message: [Python-Dev] Interning string subtype instances
- Next message: [Python-Dev] Interning string subtype instances
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]