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

Terry J. Reedy report at bugs.python.org
Fri Apr 4 22:28:58 CEST 2014


Terry J. Reedy added the comment:

While the question is reasonable, I agree with Raymond's answer. As a python programmer, I would not like to see
   d.setitem_known_hash(key, hash, d.getitem_known_hash(key, hash) + 1)

Of course, "d[key] += 1" already solves the double lookup issue at the Python level. Moreover, it abbreviates the form, rather than expanding it, which is appropriate since it abbreviates the computation.

You could optimize get-set even more than the current proposal by saving a reference to the slot corresponding to a key rather than the hash that leads to a slot. Exposing a slot reference probably breaks encapsulation too much. This could be avoided by another alternative: add PyDict_Mod(ify)Item(mapping, key, func). It would combine get and set: find slot, get item, set func(item), and return whatever SetItem does on success/failure.

----------
nosy: +terry.reedy

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


More information about the Python-bugs-list mailing list