diff options
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.55 2015/11/03 15:36:01 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 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 | */ |
@@ -22,9 +22,6 @@ | |||
22 | #include "lstring.h" | 22 | #include "lstring.h" |
23 | 23 | ||
24 | 24 | ||
25 | #define MEMERRMSG "not enough memory" | ||
26 | |||
27 | |||
28 | /* | 25 | /* |
29 | ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to | 26 | ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to |
30 | ** compute its hash | 27 | ** compute its hash |
@@ -105,7 +102,7 @@ void luaS_clearcache (global_State *g) { | |||
105 | for (i = 0; i < STRCACHE_N; i++) | 102 | for (i = 0; i < STRCACHE_N; i++) |
106 | for (j = 0; j < STRCACHE_M; j++) { | 103 | for (j = 0; j < STRCACHE_M; j++) { |
107 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ | 104 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ |
108 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ | 105 | g->strcache[i][j] = g->nfield; /* replace it with something fixed */ |
109 | } | 106 | } |
110 | } | 107 | } |
111 | 108 | ||
@@ -116,13 +113,16 @@ void luaS_clearcache (global_State *g) { | |||
116 | void luaS_init (lua_State *L) { | 113 | void luaS_init (lua_State *L) { |
117 | global_State *g = G(L); | 114 | global_State *g = G(L); |
118 | int i, j; | 115 | int i, j; |
116 | TString *memerrmsg; | ||
119 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ | 117 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ |
120 | /* pre-create memory-error message */ | 118 | /* pre-create memory-error message */ |
121 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); | 119 | memerrmsg = luaS_newliteral(L, MEMERRMSG); |
122 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ | 120 | luaC_fix(L, obj2gco(memerrmsg)); /* it should never be collected */ |
121 | g->nfield = luaS_newliteral(L, "n"); /* pre-create "n" field name */ | ||
122 | luaC_fix(L, obj2gco(g->nfield)); /* it also should never be collected */ | ||
123 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ | 123 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ |
124 | for (j = 0; j < STRCACHE_M; j++) | 124 | for (j = 0; j < STRCACHE_M; j++) |
125 | g->strcache[i][j] = g->memerrmsg; | 125 | g->strcache[i][j] = g->nfield; |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||