]> granicus.if.org Git - python/commit
Changed the dict implementation to take "string shortcuts" only when
authorTim Peters <tim.peters@gmail.com>
Fri, 14 Sep 2001 00:25:33 +0000 (00:25 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 14 Sep 2001 00:25:33 +0000 (00:25 +0000)
commit0ab085c4cba79c1743288a300425b3c9050250ba
treeaa0436b634cc45a83f710bdf94289deefd540d9b
parent742dfd6f178c3880248c32d64322e2cff8cea23f
Changed the dict implementation to take "string shortcuts" only when
keys are true strings -- no subclasses need apply.  This may be debatable.

The problem is that a str subclass may very well want to override __eq__
and/or __hash__ (see the new example of case-insensitive strings in
test_descr), but go-fast shortcuts for strings are ubiquitous in our dicts
(and subclass overrides aren't even looked for then).  Another go-fast
reason for the change is that PyCheck_StringExact() is a quicker test
than PyCheck_String(), and we make such a test on virtually every access
to every dict.

OTOH, a str subclass may also be perfectly happy using the base str eq
and hash, and this change slows them a lot.  But those cases are still
hypothetical, while Python's own reliance on true-string dicts is not.
Lib/test/test_descr.py
Objects/dictobject.c