diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-05-24 16:26:40 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-05-24 16:26:40 (GMT) |
commit | f8a548c23c13762ce739380c4d6f530b3297e16a (patch) | |
tree | ce1f5078385f1258a69065ec8ea1ae834880150f /Objects/dictobject.c | |
parent | 0c6010be75cf537e74dfa1584a19dae2247f903b (diff) | |
download | cpython-f8a548c23c13762ce739380c4d6f530b3297e16a.zip cpython-f8a548c23c13762ce739380c4d6f530b3297e16a.tar.gz cpython-f8a548c23c13762ce739380c4d6f530b3297e16a.tar.bz2 |
dictresize(): Rebuild small tables if there are any dummies, not just if
they're entirely full. Not a question of correctness, but of temporarily
misplaced common sense.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 11963ec..2854efc 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -427,16 +427,20 @@ dictresize(dictobject *mp, int minused) is_oldtable_malloced = oldtable != mp->ma_smalltable; if (newsize == MINSIZE) { - /* Either a large table is shrinking, or we can't get any - smaller. */ + /* A large table is shrinking, or we can't get any smaller. */ newtable = mp->ma_smalltable; if (newtable == oldtable) { - if (mp->ma_fill < mp->ma_size) + if (mp->ma_fill == mp->ma_used) { + /* No dummies, so no point doing anything. */ return 0; - /* The small table is entirely full. We're not - going to resise it, but need to rebuild it - anyway to purge old dummy entries. */ - assert(mp->ma_fill > mp->ma_used); /* a dummy exists */ + } + /* We're not going to resize it, but rebuild the + table anyway to purge old dummy entries. + Subtle: This is *necessary* if fill==size, + as lookdict needs at least one virgin slot to + terminate failing searches. If fill < size, it's + merely desirable, as dummies slow searches. */ + assert(mp->ma_fill > mp->ma_used); memcpy(small_copy, oldtable, sizeof(small_copy)); oldtable = small_copy; } |