aboutsummaryrefslogtreecommitdiff
path: root/llex.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-16 16:53:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-05-16 16:53:29 -0300
commit819bd51d87b799fdee029754c660dc9a5587ef57 (patch)
tree0b1ffb9a3fd591372992c72a27e4590b48236b71 /llex.c
parentf8d30826dda6ee8e99200de57a1997734b853db2 (diff)
downloadlua-819bd51d87b799fdee029754c660dc9a5587ef57.tar.gz
lua-819bd51d87b799fdee029754c660dc9a5587ef57.tar.bz2
lua-819bd51d87b799fdee029754c660dc9a5587ef57.zip
Some cleaning in the new table API
Diffstat (limited to 'llex.c')
-rw-r--r--llex.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/llex.c b/llex.c
index 5fc39a5c..9f20d3c8 100644
--- a/llex.c
+++ b/llex.c
@@ -134,13 +134,13 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
134TString *luaX_newstring (LexState *ls, const char *str, size_t l) { 134TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
135 lua_State *L = ls->L; 135 lua_State *L = ls->L;
136 TString *ts = luaS_newlstr(L, str, l); /* create new string */ 136 TString *ts = luaS_newlstr(L, str, l); /* create new string */
137 const TValue *o = luaH_getstr(ls->h, ts); 137 TString *oldts = luaH_getstrkey(ls->h, ts);
138 if (!ttisnil(o)) /* string already present? */ 138 if (oldts != NULL) /* string already present? */
139 ts = keystrval(nodefromval(o)); /* get saved copy */ 139 return oldts; /* use it */
140 else { /* not in use yet */ 140 else { /* create a new entry */
141 TValue *stv = s2v(L->top.p++); /* reserve stack space for string */ 141 TValue *stv = s2v(L->top.p++); /* reserve stack space for string */
142 setsvalue(L, stv, ts); /* temporarily anchor the string */ 142 setsvalue(L, stv, ts); /* temporarily anchor the string */
143 luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */ 143 luaH_set(L, ls->h, stv, stv); /* t[string] = string */
144 /* table is not a metatable, so it does not need to invalidate cache */ 144 /* table is not a metatable, so it does not need to invalidate cache */
145 luaC_checkGC(L); 145 luaC_checkGC(L);
146 L->top.p--; /* remove string from stack */ 146 L->top.p--; /* remove string from stack */