Selaa lähdekoodia

resize string hash table only when new size is smaller than current one

Roberto Ierusalimschy 16 vuotta sitten
vanhempi
commit
673c456cba
1 muutettua tiedostoa jossa 7 lisäystä ja 3 poistoa
  1. 7 3
      lgc.c

+ 7 - 3
lgc.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lgc.c,v 2.50 2009/04/17 14:28:06 roberto Exp roberto $
+** $Id: lgc.c,v 2.51 2009/04/28 19:04:36 roberto Exp roberto $
 ** Garbage Collector
 ** See Copyright Notice in lua.h
 */
@@ -589,8 +589,12 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, lu_mem count) {
 
 static void checkSizes (lua_State *L) {
   global_State *g = G(L);
-  if (g->strt.nuse < cast(lu_int32, g->strt.size))
-    luaS_resize(L, 1 << luaO_ceillog2(g->strt.nuse));
+  if (g->strt.nuse < cast(lu_int32, g->strt.size)) {
+    /* size could be the smaller power of 2 larger than 'nuse' */
+    int size = 1 << luaO_ceillog2(g->strt.nuse);
+    if (size < g->strt.size)  /* current table too large? */
+      luaS_resize(L, size);  /* shrink it */
+  }
   luaZ_freebuffer(L, &g->buff);
 }