[Python-Dev] Add PyDict_GetItemSetDefault() as C-API for dict.setdefault() (original) (raw)
Stefan Behnel stefan_ml at behnel.de
Thu Mar 7 08:32:59 CET 2013
- Previous message: [Python-Dev] [docs] undocumented argtypes magic in ctypes?
- Next message: [Python-Dev] PEP 434: IDLE Enhancement Exception
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
I've written a patch that adds a new C-API call for dict.setdefault(). The reason is that there is currently no way to test for a key and insert a fallback value for it without either evaluating the hash function twice or calling through the Python function. Both may involve considerable overhead and the double hash may have side-effects.
http://bugs.python.org/issue17327
It does not include an explicit test because it does not add any code over the normal dict.setdefault() implementation, which is already tested at the Python level. If you prefer having a dummy test that checks that the function is there, I don't mind adding one.
Please comment and/or apply the patch.
Thanks,
Stefan
- Previous message: [Python-Dev] [docs] undocumented argtypes magic in ctypes?
- Next message: [Python-Dev] PEP 434: IDLE Enhancement Exception
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]