aboutsummaryrefslogtreecommitdiff
path: root/llex.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--llex.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/llex.c b/llex.c
index b2e77c9c..d913db17 100644
--- a/llex.c
+++ b/llex.c
@@ -130,18 +130,15 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) {
130** Creates a new string and anchors it in scanner's table so that it 130** Creates a new string and anchors it in scanner's table so that it
131** will not be collected until the end of the compilation; by that time 131** will not be collected until the end of the compilation; by that time
132** it should be anchored somewhere. It also internalizes long strings, 132** it should be anchored somewhere. It also internalizes long strings,
133** ensuring there is only one copy of each unique string. The table 133** ensuring there is only one copy of each unique string.
134** here is used as a set: the string enters as the key, while its value
135** is irrelevant. We use the string itself as the value only because it
136** is a TValue readily available. Later, the code generation can change
137** this value.
138*/ 134*/
139TString *luaX_newstring (LexState *ls, const char *str, size_t l) { 135TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
140 lua_State *L = ls->L; 136 lua_State *L = ls->L;
141 TString *ts = luaS_newlstr(L, str, l); /* create new string */ 137 TString *ts = luaS_newlstr(L, str, l); /* create new string */
142 TString *oldts = luaH_getstrkey(ls->h, ts); 138 TValue oldts;
143 if (oldts != NULL) /* string already present? */ 139 int tag = luaH_getstr(ls->h, ts, &oldts);
144 return oldts; /* use it */ 140 if (!tagisempty(tag)) /* string already present? */
141 return tsvalue(&oldts); /* use stored value */
145 else { /* create a new entry */ 142 else { /* create a new entry */
146 TValue *stv = s2v(L->top.p++); /* reserve stack space for string */ 143 TValue *stv = s2v(L->top.p++); /* reserve stack space for string */
147 setsvalue(L, stv, ts); /* temporarily anchor the string */ 144 setsvalue(L, stv, ts); /* temporarily anchor the string */
@@ -149,8 +146,8 @@ TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
149 /* table is not a metatable, so it does not need to invalidate cache */ 146 /* table is not a metatable, so it does not need to invalidate cache */
150 luaC_checkGC(L); 147 luaC_checkGC(L);
151 L->top.p--; /* remove string from stack */ 148 L->top.p--; /* remove string from stack */
149 return ts;
152 } 150 }
153 return ts;
154} 151}
155 152
156 153