commit 673c456cbaf8d37e9e71afd2bedc00654235f90d
parent ea445708839d48f03d32817071e5fce1e08c3927
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 29 Apr 2009 14:09:17 -0300
resize string hash table only when new size is smaller than current one
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/lgc.c b/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);
}