From 6d998055c80a0fe8d4698ba02becb1813203eee9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 27 Jul 2017 10:50:16 -0300 Subject: no more reference 'memerrmsg' + new reference to "n" (both can be retrieved by 'luaS_newliteral' without creating anything, because they are fixed, but "n" deserves fast access while 'memerrmsg' does not) --- lstring.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lstring.c') diff --git a/lstring.c b/lstring.c index fc9eb220..a851fd74 100644 --- a/lstring.c +++ b/lstring.c @@ -1,5 +1,5 @@ /* -** $Id: lstring.c,v 2.55 2015/11/03 15:36:01 roberto Exp roberto $ +** $Id: lstring.c,v 2.56 2015/11/23 11:32:51 roberto Exp roberto $ ** String table (keeps all strings handled by Lua) ** See Copyright Notice in lua.h */ @@ -22,9 +22,6 @@ #include "lstring.h" -#define MEMERRMSG "not enough memory" - - /* ** Lua will use at most ~(2^LUAI_HASHLIMIT) bytes from a string to ** compute its hash @@ -105,7 +102,7 @@ void luaS_clearcache (global_State *g) { for (i = 0; i < STRCACHE_N; i++) for (j = 0; j < STRCACHE_M; j++) { if (iswhite(g->strcache[i][j])) /* will entry be collected? */ - g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ + g->strcache[i][j] = g->nfield; /* replace it with something fixed */ } } @@ -116,13 +113,16 @@ void luaS_clearcache (global_State *g) { void luaS_init (lua_State *L) { global_State *g = G(L); int i, j; + TString *memerrmsg; luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ /* pre-create memory-error message */ - g->memerrmsg = luaS_newliteral(L, MEMERRMSG); - luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ + memerrmsg = luaS_newliteral(L, MEMERRMSG); + luaC_fix(L, obj2gco(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 (j = 0; j < STRCACHE_M; j++) - g->strcache[i][j] = g->memerrmsg; + g->strcache[i][j] = g->nfield; } -- cgit v1.2.3-55-g6feb