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 <rep...@bugs.python.org>
<http://bugs.python.org/issue21101>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to