Some cleaning in the new table API

This commit is contained in:
Roberto Ierusalimschy
2023-05-16 16:53:29 -03:00
parent f8d30826dd
commit 819bd51d87
8 changed files with 190 additions and 211 deletions

10
llex.c
View File

@@ -134,13 +134,13 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
lua_State *L = ls->L;
TString *ts = luaS_newlstr(L, str, l); /* create new string */
const TValue *o = luaH_getstr(ls->h, ts);
if (!ttisnil(o)) /* string already present? */
ts = keystrval(nodefromval(o)); /* get saved copy */
else { /* not in use yet */
TString *oldts = luaH_getstrkey(ls->h, ts);
if (oldts != NULL) /* string already present? */
return oldts; /* use it */
else { /* create a new entry */
TValue *stv = s2v(L->top.p++); /* reserve stack space for string */
setsvalue(L, stv, ts); /* temporarily anchor the string */
luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */
luaH_set(L, ls->h, stv, stv); /* t[string] = string */
/* table is not a metatable, so it does not need to invalidate cache */
luaC_checkGC(L);
L->top.p--; /* remove string from stack */