diff options
-rw-r--r-- | lstate.h | 4 | ||||
-rw-r--r-- | lstring.c | 18 |
2 files changed, 11 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.120 2015/03/04 13:31:21 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.121 2015/04/10 17:56:25 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -141,7 +141,7 @@ typedef struct global_State { | |||
141 | TString *memerrmsg; /* memory-error message */ | 141 | TString *memerrmsg; /* memory-error message */ |
142 | TString *tmname[TM_N]; /* array with tag-method names */ | 142 | TString *tmname[TM_N]; /* array with tag-method names */ |
143 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ | 143 | struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */ |
144 | TString *strcache[STRCACHE_SIZE]; /* cache for strings in API */ | 144 | TString *strcache[STRCACHE_SIZE][1]; /* cache for strings in API */ |
145 | } global_State; | 145 | } global_State; |
146 | 146 | ||
147 | 147 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.47 2015/03/04 13:31:21 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.48 2015/03/25 13:42:19 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -94,8 +94,8 @@ void luaS_resize (lua_State *L, int newsize) { | |||
94 | void luaS_clearcache (global_State *g) { | 94 | void luaS_clearcache (global_State *g) { |
95 | int i; | 95 | int i; |
96 | for (i = 0; i < STRCACHE_SIZE; i++) { | 96 | for (i = 0; i < STRCACHE_SIZE; i++) { |
97 | if (iswhite(g->strcache[i])) /* will entry be collected? */ | 97 | if (iswhite(g->strcache[i][0])) /* will entry be collected? */ |
98 | g->strcache[i] = g->memerrmsg; /* replace it with something fixed */ | 98 | g->strcache[i][0] = g->memerrmsg; /* replace it with something fixed */ |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
@@ -110,8 +110,8 @@ void luaS_init (lua_State *L) { | |||
110 | /* pre-create memory-error message */ | 110 | /* pre-create memory-error message */ |
111 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); | 111 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); |
112 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ | 112 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ |
113 | for (i = 0; i < STRCACHE_SIZE; i++) | 113 | for (i = 0; i < STRCACHE_SIZE; i++) /* fill cache with valid strings */ |
114 | g->strcache[i] = g->memerrmsg; /* fill cache with valid strings */ | 114 | g->strcache[i][0] = g->memerrmsg; |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
@@ -200,12 +200,12 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
200 | */ | 200 | */ |
201 | TString *luaS_new (lua_State *L, const char *str) { | 201 | TString *luaS_new (lua_State *L, const char *str) { |
202 | unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */ | 202 | unsigned int i = point2uint(str) % STRCACHE_SIZE; /* hash */ |
203 | TString **p = &G(L)->strcache[i]; | 203 | TString **p = G(L)->strcache[i]; |
204 | if (strcmp(str, getstr(*p)) == 0) /* hit? */ | 204 | if (strcmp(str, getstr(p[0])) == 0) /* hit? */ |
205 | return *p; /* that it is */ | 205 | return p[0]; /* that it is */ |
206 | else { /* normal route */ | 206 | else { /* normal route */ |
207 | TString *s = luaS_newlstr(L, str, strlen(str)); | 207 | TString *s = luaS_newlstr(L, str, strlen(str)); |
208 | *p = s; | 208 | p[0] = s; |
209 | return s; | 209 | return s; |
210 | } | 210 | } |
211 | } | 211 | } |