lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 6645bb2df44d4fc6c7aea8347a559357b657f80a
parent 02aed045def21789f7adad29a11da75cae118e44
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Mon,  1 Jun 2015 13:34:12 -0300

'strcache' elements as arrays of 1 element hints that cache can
be n-way (instead of direct mapped)

Diffstat:
Mlstate.h | 4++--
Mlstring.c | 18+++++++++---------
2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lstate.h b/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; diff --git a/lstring.c b/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; } }