Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8a548c

Browse files
committed
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.
1 parent 0c6010b commit f8a548c

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Objects/dictobject.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,16 +427,20 @@ dictresize(dictobject *mp, int minused)
427427
is_oldtable_malloced = oldtable != mp->ma_smalltable;
428428

429429
if (newsize == MINSIZE) {
430-
/* Either a large table is shrinking, or we can't get any
431-
smaller. */
430+
/* A large table is shrinking, or we can't get any smaller. */
432431
newtable = mp->ma_smalltable;
433432
if (newtable == oldtable) {
434-
if (mp->ma_fill < mp->ma_size)
433+
if (mp->ma_fill == mp->ma_used) {
434+
/* No dummies, so no point doing anything. */
435435
return 0;
436-
/* The small table is entirely full. We're not
437-
going to resise it, but need to rebuild it
438-
anyway to purge old dummy entries. */
439-
assert(mp->ma_fill > mp->ma_used); /* a dummy exists */
436+
}
437+
/* We're not going to resize it, but rebuild the
438+
table anyway to purge old dummy entries.
439+
Subtle: This is *necessary* if fill==size,
440+
as lookdict needs at least one virgin slot to
441+
terminate failing searches. If fill < size, it's
442+
merely desirable, as dummies slow searches. */
443+
assert(mp->ma_fill > mp->ma_used);
440444
memcpy(small_copy, oldtable, sizeof(small_copy));
441445
oldtable = small_copy;
442446
}

0 commit comments

Comments
 (0)