@@ -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