mirror of
https://github.com/lua/lua
synced 2025-03-21 05:02:57 +03:00
'strcache' elements as arrays of 1 element hints that cache can
be n-way (instead of direct mapped)
This commit is contained in:
parent
02aed045de
commit
6645bb2df4
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
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -141,7 +141,7 @@ typedef struct global_State {
|
||||
TString *memerrmsg; /* memory-error message */
|
||||
TString *tmname[TM_N]; /* array with tag-method names */
|
||||
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;
|
||||
|
||||
|
||||
|
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)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -94,8 +94,8 @@ void luaS_resize (lua_State *L, int newsize) {
|
||||
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 */
|
||||
if (iswhite(g->strcache[i][0])) /* will entry be collected? */
|
||||
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 */
|
||||
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
|
||||
luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
|
||||
for (i = 0; i < STRCACHE_SIZE; i++)
|
||||
g->strcache[i] = g->memerrmsg; /* fill cache with valid strings */
|
||||
for (i = 0; i < STRCACHE_SIZE; i++) /* 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) {
|
||||
unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */
|
||||
TString **p = &G(L)->strcache[i];
|
||||
if (strcmp(str, getstr(*p)) == 0) /* hit? */
|
||||
return *p; /* that it is */
|
||||
TString **p = G(L)->strcache[i];
|
||||
if (strcmp(str, getstr(p[0])) == 0) /* hit? */
|
||||
return p[0]; /* that it is */
|
||||
else { /* normal route */
|
||||
TString *s = luaS_newlstr(L, str, strlen(str));
|
||||
*p = s;
|
||||
p[0] = s;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user