mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
no more 'nfield' string
This commit is contained in:
parent
0682fe8169
commit
c7a8cba745
4
lstate.h
4
lstate.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstate.h,v 2.153 2017/12/19 16:40:17 roberto Exp roberto $
|
** $Id: lstate.h,v 2.154 2018/02/09 15:16:06 roberto Exp roberto $
|
||||||
** Global State
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -176,7 +176,7 @@ typedef struct global_State {
|
|||||||
lua_CFunction panic; /* to be called in unprotected errors */
|
lua_CFunction panic; /* to be called in unprotected errors */
|
||||||
struct lua_State *mainthread;
|
struct lua_State *mainthread;
|
||||||
const lua_Number *version; /* pointer to version number */
|
const lua_Number *version; /* pointer to version number */
|
||||||
TString *nfield; /* string "n" (key in vararg tables) */
|
TString *memerrmsg; /* message for memory-allocation errors */
|
||||||
TString *tmname[TM_N]; /* array with tag-method names */
|
TString *tmname[TM_N]; /* array with tag-method names */
|
||||||
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
||||||
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
||||||
|
13
lstring.c
13
lstring.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstring.c,v 2.62 2017/12/18 13:00:57 roberto Exp roberto $
|
** $Id: lstring.c,v 2.63 2018/01/28 15:13:26 roberto Exp roberto $
|
||||||
** String table (keeps all strings handled by Lua)
|
** String table (keeps all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -122,7 +122,7 @@ void luaS_clearcache (global_State *g) {
|
|||||||
for (i = 0; i < STRCACHE_N; i++)
|
for (i = 0; i < STRCACHE_N; i++)
|
||||||
for (j = 0; j < STRCACHE_M; j++) {
|
for (j = 0; j < STRCACHE_M; j++) {
|
||||||
if (iswhite(g->strcache[i][j])) /* will entry be collected? */
|
if (iswhite(g->strcache[i][j])) /* will entry be collected? */
|
||||||
g->strcache[i][j] = g->nfield; /* replace it with something fixed */
|
g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,19 +133,16 @@ void luaS_clearcache (global_State *g) {
|
|||||||
void luaS_init (lua_State *L) {
|
void luaS_init (lua_State *L) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
int i, j;
|
int i, j;
|
||||||
TString *memerrmsg;
|
|
||||||
stringtable *tb = &G(L)->strt;
|
stringtable *tb = &G(L)->strt;
|
||||||
tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*);
|
tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*);
|
||||||
tablerehash(tb->hash, 0, MINSTRTABSIZE); /* clear array */
|
tablerehash(tb->hash, 0, MINSTRTABSIZE); /* clear array */
|
||||||
tb->size = MINSTRTABSIZE;
|
tb->size = MINSTRTABSIZE;
|
||||||
/* pre-create memory-error message */
|
/* pre-create memory-error message */
|
||||||
memerrmsg = luaS_newliteral(L, MEMERRMSG);
|
g->memerrmsg = luaS_newliteral(L, MEMERRMSG);
|
||||||
luaC_fix(L, obj2gco(memerrmsg)); /* it should never be collected */
|
luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
|
||||||
g->nfield = luaS_newliteral(L, "n"); /* pre-create "n" field name */
|
|
||||||
luaC_fix(L, obj2gco(g->nfield)); /* it also should never be collected */
|
|
||||||
for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */
|
for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */
|
||||||
for (j = 0; j < STRCACHE_M; j++)
|
for (j = 0; j < STRCACHE_M; j++)
|
||||||
g->strcache[i][j] = g->nfield;
|
g->strcache[i][j] = g->memerrmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user