From 673c456cbaf8d37e9e71afd2bedc00654235f90d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 29 Apr 2009 14:09:41 -0300 Subject: [PATCH] resize string hash table only when new size is smaller than current one --- lgc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lgc.c b/lgc.c index a170ab1c..9563da82 100644 --- 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); }