Slightly faster way to check for "global"

This commit is contained in:
Roberto Ierusalimschy
2025-05-16 14:51:07 -03:00
parent 3fb7a77731
commit ded2ad2d86
3 changed files with 13 additions and 12 deletions

View File

@@ -2001,10 +2001,10 @@ static void statement (LexState *ls) {
case TK_NAME: {
/* compatibility code to parse global keyword when "global"
is not reserved */
if (strcmp(getstr(ls->t.seminfo.ts), "global") == 0) {
if (ls->t.seminfo.ts == ls->glbn) { /* current = "global"? */
int lk = luaX_lookahead(ls);
if (lk == TK_NAME || lk == '*' || lk == TK_FUNCTION) {
/* 'global <name>' or 'global *' or 'global function' */
/* 'global name' or 'global *' or 'global function' */
globalstatfunc(ls, line);
break;
}