Message31110
ked-tao: as for "doesn't really explain", please take a look at this comment:
/* Set ep to "the first" dict entry with a value. We abuse the hash
* field of slot 0 to hold a search finger:
* If slot 0 has a value, use slot 0.
* Else slot 0 is being used to hold a search finger,
* and we use its hash value as the first index to look.
*/
So .popitem first returns (and removes) the item in slot 0. Afterwards, it does a
linear scan through the dictionary, returning one item at a time. To avoid
re-scanning the emptying dictionary over and over again, the me_hash
value of slot 0 indicates the place to start searching when the next .popitem
call is made. Of course, this value may start out bogus and out-of-range,
or may become out-of-range if the dictionary shrinks; in that case, it
starts over at index 1. If it is bogus (i.e. never set as a search finger)
and in-range, that's fine: it will just start searching for a non-empty
slot at me_hash.
Because it is a slot number, me_hash must be large enough to hold a
Py_ssize_t. On some systems (Win64 in particular), long is not large
enough to hold Py_ssize_t.
I believe the proposed patch is fine. |
|
Date |
User |
Action |
Args |
2007-08-23 14:51:35 | admin | link | issue1646068 messages |
2007-08-23 14:51:35 | admin | create | |
|