'strcache' elements as arrays of 1 element hints that cache can
be n-way (instead of direct mapped)
This commit is contained in:
4
lstate.h
4
lstate.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstate.h,v 2.120 2015/03/04 13:31:21 roberto Exp roberto $
|
** $Id: lstate.h,v 2.121 2015/04/10 17:56:25 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -141,7 +141,7 @@ typedef struct global_State {
|
|||||||
TString *memerrmsg; /* memory-error message */
|
TString *memerrmsg; /* memory-error message */
|
||||||
TString *tmname[TM_N]; /* array with tag-method names */
|
TString *tmname[TM_N]; /* array with tag-method names */
|
||||||
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
||||||
TString *strcache[STRCACHE_SIZE]; /* cache for strings in API */
|
TString *strcache[STRCACHE_SIZE][1]; /* cache for strings in API */
|
||||||
} global_State;
|
} global_State;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
lstring.c
18
lstring.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstring.c,v 2.47 2015/03/04 13:31:21 roberto Exp roberto $
|
** $Id: lstring.c,v 2.48 2015/03/25 13:42:19 roberto Exp roberto $
|
||||||
** String table (keeps all strings handled by Lua)
|
** String table (keeps all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -94,8 +94,8 @@ void luaS_resize (lua_State *L, int newsize) {
|
|||||||
void luaS_clearcache (global_State *g) {
|
void luaS_clearcache (global_State *g) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < STRCACHE_SIZE; i++) {
|
for (i = 0; i < STRCACHE_SIZE; i++) {
|
||||||
if (iswhite(g->strcache[i])) /* will entry be collected? */
|
if (iswhite(g->strcache[i][0])) /* will entry be collected? */
|
||||||
g->strcache[i] = g->memerrmsg; /* replace it with something fixed */
|
g->strcache[i][0] = g->memerrmsg; /* replace it with something fixed */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,8 +110,8 @@ void luaS_init (lua_State *L) {
|
|||||||
/* pre-create memory-error message */
|
/* pre-create memory-error message */
|
||||||
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
|
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
|
||||||
luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
|
luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
|
||||||
for (i = 0; i < STRCACHE_SIZE; i++)
|
for (i = 0; i < STRCACHE_SIZE; i++) /* fill cache with valid strings */
|
||||||
g->strcache[i] = g->memerrmsg; /* fill cache with valid strings */
|
g->strcache[i][0] = g->memerrmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -200,12 +200,12 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
|
|||||||
*/
|
*/
|
||||||
TString *luaS_new (lua_State *L, const char *str) {
|
TString *luaS_new (lua_State *L, const char *str) {
|
||||||
unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */
|
unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */
|
||||||
TString **p = &G(L)->strcache[i];
|
TString **p = G(L)->strcache[i];
|
||||||
if (strcmp(str, getstr(*p)) == 0) /* hit? */
|
if (strcmp(str, getstr(p[0])) == 0) /* hit? */
|
||||||
return *p; /* that it is */
|
return p[0]; /* that it is */
|
||||||
else { /* normal route */
|
else { /* normal route */
|
||||||
TString *s = luaS_newlstr(L, str, strlen(str));
|
TString *s = luaS_newlstr(L, str, strlen(str));
|
||||||
*p = s;
|
p[0] = s;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user