aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-06-01 13:34:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-06-01 13:34:37 -0300
commit6645bb2df44d4fc6c7aea8347a559357b657f80a (patch)
tree787784229b0de5d41fea6bf8475656063db7af27 /lstring.c
parent02aed045def21789f7adad29a11da75cae118e44 (diff)
downloadlua-6645bb2df44d4fc6c7aea8347a559357b657f80a.tar.gz
lua-6645bb2df44d4fc6c7aea8347a559357b657f80a.tar.bz2
lua-6645bb2df44d4fc6c7aea8347a559357b657f80a.zip
'strcache' elements as arrays of 1 element hints that cache can
be n-way (instead of direct mapped)
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lstring.c b/lstring.c
index 5af5050b..5788c9e6 100644
--- a/lstring.c
+++ b/lstring.c
@@ -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) {
94void luaS_clearcache (global_State *g) { 94void 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*/
201TString *luaS_new (lua_State *L, const char *str) { 201TString *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}