Scanner and parser use different tables for constants

Moreover, each function being parsed has its own table.

The code is cleaner when each table is used for one specific purpose:
The scanner uses its table to anchor and unify strings, mapping strings
to themselves; the parser uses it to reuse constants in the code,
mapping constants to their indices in the constant table. A different
table for each task avoids false collisions.
This commit is contained in:
Roberto Ierusalimschy
2024-12-17 11:23:22 -03:00
parent 7538f3886d
commit 1c40ff9faa
6 changed files with 20 additions and 28 deletions

View File

@@ -962,7 +962,7 @@ lu_byte luaH_getint (Table *t, lua_Integer key, TValue *res) {
*/
const TValue *luaH_Hgetshortstr (Table *t, TString *key) {
Node *n = hashstr(t, key);
lua_assert(key->tt == LUA_VSHRSTR);
lua_assert(strisshr(key));
for (;;) { /* check whether 'key' is somewhere in the chain */
if (keyisshrstr(n) && eqshrstr(keystrval(n), key))
return gval(n); /* that's it */
@@ -997,15 +997,6 @@ lu_byte luaH_getstr (Table *t, TString *key, TValue *res) {
}
TString *luaH_getstrkey (Table *t, TString *key) {
const TValue *o = Hgetstr(t, key);
if (!isabstkey(o)) /* string already present? */
return keystrval(nodefromval(o)); /* get saved copy */
else
return NULL;
}
/*
** main search function
*/