diff options
Diffstat (limited to 'llex.c')
| -rw-r--r-- | llex.c | 15 |
1 files changed, 9 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.67 2013/06/19 14:27:00 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.68 2013/08/21 20:09:51 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -119,22 +119,25 @@ l_noret luaX_syntaxerror (LexState *ls, const char *msg) { | |||
| 119 | 119 | ||
| 120 | 120 | ||
| 121 | /* | 121 | /* |
| 122 | ** creates a new string and anchors it in function's table so that | 122 | ** creates a new string and anchors it in scanner's table so that |
| 123 | ** it will not be collected until the end of the function's compilation | 123 | ** it will not be collected until the end of the compilation |
| 124 | ** (by that time it should be anchored in function's prototype) | 124 | ** (by that time it should be anchored somewhere) |
| 125 | */ | 125 | */ |
| 126 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { | 126 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { |
| 127 | lua_State *L = ls->L; | 127 | lua_State *L = ls->L; |
| 128 | TValue *o; /* entry for `str' */ | 128 | TValue *o; /* entry for `str' */ |
| 129 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ | 129 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 130 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ | 130 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
| 131 | o = luaH_set(L, ls->fs->h, L->top - 1); | 131 | o = luaH_set(L, ls->h, L->top - 1); |
| 132 | if (ttisnil(o)) { /* not in use yet? (see 'addK') */ | 132 | if (ttisnil(o)) { /* not in use yet? */ |
| 133 | /* boolean value does not need GC barrier; | 133 | /* boolean value does not need GC barrier; |
| 134 | table has no metatable, so it does not need to invalidate cache */ | 134 | table has no metatable, so it does not need to invalidate cache */ |
| 135 | setbvalue(o, 1); /* t[string] = true */ | 135 | setbvalue(o, 1); /* t[string] = true */ |
| 136 | luaC_checkGC(L); | 136 | luaC_checkGC(L); |
| 137 | } | 137 | } |
| 138 | else { /* string already present */ | ||
| 139 | ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */ | ||
| 140 | } | ||
| 138 | L->top--; /* remove string from stack */ | 141 | L->top--; /* remove string from stack */ |
| 139 | return ts; | 142 | return ts; |
| 140 | } | 143 | } |
