From 6ca7b63bce0ce4f1abf418dead256d3e51e41644 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 11 Sep 2013 11:56:15 -0300 Subject: [PATCH] check for shrinking string table done only at the end of a GC cycle --- lgc.c | 15 ++++++++++----- lstring.c | 4 +--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lgc.c b/lgc.c index be6ca0c1..62e3777f 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.162 2013/09/11 14:09:55 roberto Exp roberto $ +** $Id: lgc.c,v 2.163 2013/09/11 14:47:08 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -759,10 +759,15 @@ static GCObject **sweeptolive (lua_State *L, GCObject **p, int *n) { ** ======================================================= */ -static void checkBuffer (lua_State *L) { - global_State *g = G(L); - if (g->gckind != KGC_EMERGENCY) +/* +** If possible, free concatenation buffer and shrink string table +*/ +static void checkSizes (lua_State *L, global_State *g) { + if (g->gckind != KGC_EMERGENCY) { luaZ_freebuffer(L, &g->buff); /* free concatenation buffer */ + if (g->strt.nuse < g->strt.size / 4) /* string table too big? */ + luaS_resize(L, g->strt.size / 2); /* shrink it a little */ + } } @@ -1171,7 +1176,7 @@ static lu_mem singlestep (lua_State *L) { } case GCSswpend: { /* finish sweeps */ makewhite(g, obj2gco(g->mainthread)); /* sweep main thread */ - checkBuffer(L); + checkSizes(L, g); g->gcstate = GCSpause; /* finish collection */ return GCSWEEPCOST; } diff --git a/lstring.c b/lstring.c index bd40841d..c73e521c 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.34 2013/09/05 19:31:49 roberto Exp roberto $ +** $Id: lstring.c,v 2.35 2013/09/11 12:26:14 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -118,8 +118,6 @@ LUAI_FUNC void luaS_remove (lua_State *L, TString *ts) { p = &(*p)->tsv.hnext; *p = (*p)->tsv.hnext; /* remove element from its list */ tb->nuse--; - if (tb->nuse < tb->size/4) - luaS_resize(L, tb->size/2); }