This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Arfrever, alex, josh.r, pitrou, rhettinger, serhiy.storchaka, terry.reedy
Date 2014-04-04.20:28:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396643338.08.0.722924597032.issue21101@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-04-04 20:28:58terry.reedysetrecipients: + terry.reedy, rhettinger, pitrou, Arfrever, alex, serhiy.storchaka, josh.r
2014-04-04 20:28:58terry.reedysetmessageid: <1396643338.08.0.722924597032.issue21101@psf.upfronthosting.co.za>
2014-04-04 20:28:58terry.reedylinkissue21101 messages
2014-04-04 20:28:57terry.reedycreate