Skip to content

Commit b436ed5

Browse files
committed
'clearapihash' -> 'luaS_clearcache' and moved to 'lstring.c' (which
keeps all code related to this cache)
1 parent 2b37f21 commit b436ed5

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

lgc.c

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lgc.c,v 2.203 2015/03/04 13:31:21 roberto Exp roberto $
2+
** $Id: lgc.c,v 2.204 2015/03/04 13:51:55 roberto Exp roberto $
33
** Garbage Collector
44
** See Copyright Notice in lua.h
55
*/
@@ -977,19 +977,6 @@ void luaC_freeallobjects (lua_State *L) {
977977
}
978978

979979

980-
/*
981-
** Clear API string cache. (Entries cannot be empty, so fill them with
982-
** a non-collectable string.)
983-
*/
984-
static void clearapihash (global_State *g) {
985-
int i;
986-
for (i = 0; i < STRCACHE_SIZE; i++) {
987-
if (iswhite(g->strcache[i])) /* will entry be collected? */
988-
g->strcache[i] = g->memerrmsg; /* replace it with something fixed */
989-
}
990-
}
991-
992-
993980
static l_mem atomic (lua_State *L) {
994981
global_State *g = G(L);
995982
l_mem work;
@@ -1030,7 +1017,7 @@ static l_mem atomic (lua_State *L) {
10301017
/* clear values from resurrected weak tables */
10311018
clearvalues(g, g->weak, origweak);
10321019
clearvalues(g, g->allweak, origall);
1033-
clearapihash(g);
1020+
luaS_clearcache(g);
10341021
g->currentwhite = cast_byte(otherwhite(g)); /* flip current white */
10351022
work += g->GCmemtrav; /* complete counting */
10361023
return work; /* estimate of memory marked by 'atomic' */

lstring.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lstring.c,v 2.46 2015/01/16 16:54:37 roberto Exp roberto $
2+
** $Id: lstring.c,v 2.47 2015/03/04 13:31:21 roberto Exp roberto $
33
** String table (keeps all strings handled by Lua)
44
** See Copyright Notice in lua.h
55
*/
@@ -87,6 +87,19 @@ void luaS_resize (lua_State *L, int newsize) {
8787
}
8888

8989

90+
/*
91+
** Clear API string cache. (Entries cannot be empty, so fill them with
92+
** a non-collectable string.)
93+
*/
94+
void luaS_clearcache (global_State *g) {
95+
int i;
96+
for (i = 0; i < STRCACHE_SIZE; i++) {
97+
if (iswhite(g->strcache[i])) /* will entry be collected? */
98+
g->strcache[i] = g->memerrmsg; /* replace it with something fixed */
99+
}
100+
}
101+
102+
90103
/*
91104
** Initialize the string table and the string cache
92105
*/

lstring.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lstring.h,v 1.57 2015/01/16 16:54:37 roberto Exp roberto $
2+
** $Id: lstring.h,v 1.58 2015/03/04 13:31:21 roberto Exp roberto $
33
** String table (keep all strings handled by Lua)
44
** See Copyright Notice in lua.h
55
*/
@@ -36,6 +36,7 @@
3636
LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed);
3737
LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b);
3838
LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
39+
LUAI_FUNC void luaS_clearcache (global_State *g);
3940
LUAI_FUNC void luaS_init (lua_State *L);
4041
LUAI_FUNC void luaS_remove (lua_State *L, TString *ts);
4142
LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s);

0 commit comments

Comments
 (0)