Michael Hudson <mwh21@cam.ac.uk> writes: > Guido van Rossum <guido@digicool.com> writes: > > > Checking for a dup key in PyDict_SetItem() before calling dictresize() > > slows things down. Checking in insertdict() is wrong because > > dictresize() uses that! > > Maybe you could do the check for resize *after* the call to > insertdict? I think that would work, but I wouldn't like to go > messing with such a performance critical bit of code without some > careful thinking. Indeed; this tiny little patch: Index: Objects/dictobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v retrieving revision 2.73 diff -c -r2.73 dictobject.c *** Objects/dictobject.c 2001/01/18 00:39:02 2.73 --- Objects/dictobject.c 2001/03/20 13:38:04 *************** *** 496,501 **** --- 496,508 ---- Py_INCREF(value); Py_INCREF(key); insertdict(mp, key, hash, value); + /* if fill >= 2/3 size, double in size */ + if (mp->ma_fill*3 >= mp->ma_size*2) { + if (dictresize(mp, mp->ma_used*2) != 0) { + if (mp->ma_fill+1 > mp->ma_size) + return -1; + } + } return 0; } fixes Ping's reported crash. You can't naively (as I did at first) *only* check after the insertdict, 'cause dicts are created with 0 size. Currently building from scratch to do some performance testing. Cheers, M. -- It's a measure of how much I love Python that I moved to VA, where if things don't work out Guido will buy a plantation and put us to work harvesting peanuts instead. -- Tim Peters, comp.lang.python
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4