From b436ed58a3416c2e1936bdce880ac09925401a87 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 25 Mar 2015 10:42:19 -0300 Subject: [PATCH] 'clearapihash' -> 'luaS_clearcache' and moved to 'lstring.c' (which keeps all code related to this cache) --- lgc.c | 17 ++--------------- lstring.c | 15 ++++++++++++++- lstring.h | 3 ++- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lgc.c b/lgc.c index 3bc0740b..5823cb6b 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 2.203 2015/03/04 13:31:21 roberto Exp roberto $ +** $Id: lgc.c,v 2.204 2015/03/04 13:51:55 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -977,19 +977,6 @@ void luaC_freeallobjects (lua_State *L) { } -/* -** Clear API string cache. (Entries cannot be empty, so fill them with -** a non-collectable string.) -*/ -static void clearapihash (global_State *g) { - int i; - for (i = 0; i < STRCACHE_SIZE; i++) { - if (iswhite(g->strcache[i])) /* will entry be collected? */ - g->strcache[i] = g->memerrmsg; /* replace it with something fixed */ - } -} - - static l_mem atomic (lua_State *L) { global_State *g = G(L); l_mem work; @@ -1030,7 +1017,7 @@ static l_mem atomic (lua_State *L) { /* clear values from resurrected weak tables */ clearvalues(g, g->weak, origweak); clearvalues(g, g->allweak, origall); - clearapihash(g); + luaS_clearcache(g); g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */ work += g->GCmemtrav; /* complete counting */ return work; /* estimate of memory marked by 'atomic' */ diff --git a/lstring.c b/lstring.c index 638f3dec..5af5050b 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.46 2015/01/16 16:54:37 roberto Exp roberto $ +** $Id: lstring.c,v 2.47 2015/03/04 13:31:21 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -87,6 +87,19 @@ void luaS_resize (lua_State *L, int newsize) { } +/* +** Clear API string cache. (Entries cannot be empty, so fill them with +** a non-collectable string.) +*/ +void luaS_clearcache (global_State *g) { + int i; + for (i = 0; i < STRCACHE_SIZE; i++) { + if (iswhite(g->strcache[i])) /* will entry be collected? */ + g->strcache[i] = g->memerrmsg; /* replace it with something fixed */ + } +} + + /* ** Initialize the string table and the string cache */ diff --git a/lstring.h b/lstring.h index 2b06afaf..cba3cb28 100644 --- a/lstring.h +++ b/lstring.h @@ -1,5 +1,5 @@ /* -** $Id: lstring.h,v 1.57 2015/01/16 16:54:37 roberto Exp roberto $ +** $Id: lstring.h,v 1.58 2015/03/04 13:31:21 roberto Exp roberto $ ** String table (keep all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -36,6 +36,7 @@ LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); LUAI_FUNC void luaS_resize (lua_State *L, int newsize); +LUAI_FUNC void luaS_clearcache (global_State *g); LUAI_FUNC void luaS_init (lua_State *L); LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s);