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

This commit is contained in:
Roberto Ierusalimschy 2009-04-29 14:09:41 -03:00
parent ea44570883
commit 673c456cba
1 changed files with 7 additions and 3 deletions

10
lgc.c
View File

@ -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);
}