[issue21101] Extend the PyDict C API to handle cases where the hash value is known

Alex Gaynor report at bugs.python.org
Fri Apr 4 22:31:19 CEST 2014


Alex Gaynor added the comment:

d[key] += 1 still does two dict lookups, and invokes the hash function twice:

>>> class X(object):
...   def __hash__(self):
...     print "hashed"
...     return 0
...   def __eq__(self, other):
...     return True
...
>>> d = {X(): 0}
hashed
>>> d[X()]
hashed
0
>>> d[X()] = 3
hashed
>>> d[X()] += 1
hashed
hashed

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21101>
_______________________________________


More information about the Python-bugs-list mailing list