From 9ff881e381c065b5018fca96b0f745ea563f1450 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 2 Sep 2026 17:39:41 -0700 Subject: [PATCH] Parser: reduce variable reference payload Store the atom identifier and resolved variable directly in parser nodes and move the undefined-reference flag into the common node flags. This removes the separately allocated reference object and helps reduce parser nodes to the 64-byte memory-pool class. --- src/njs_generator.c | 4 +++- src/njs_parser.c | 5 ----- src/njs_parser.h | 1 + src/njs_variable.c | 3 +-- src/njs_variable.h | 3 --- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/njs_generator.c b/src/njs_generator.c index 54e3eca4..dd6b7111 100644 --- a/src/njs_generator.c +++ b/src/njs_generator.c @@ -6360,7 +6360,9 @@ njs_generate_reference_error(njs_vm_t *vm, njs_generator_t *generator, njs_str_t entry; njs_vmcode_error_t *ref_err; - if (njs_slow_path(!node->u.reference.not_defined)) { + entry = njs_str_value("unknown"); + + if (njs_slow_path(!node->not_defined)) { njs_internal_error(vm, "variable is not defined but not_defined " "is not set"); return NJS_ERROR; diff --git a/src/njs_parser.c b/src/njs_parser.c index 66d105e9..a278824b 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -3696,10 +3696,6 @@ njs_parser_unary_expression_next(njs_parser_t *parser, } } - if (type == NJS_TOKEN_TYPEOF && node->token_type == NJS_TOKEN_NAME) { - node->u.reference.type = NJS_TYPEOF; - } - parser->target->left = parser->node; parser->target->left->dest = parser->target; parser->node = parser->target; @@ -8986,7 +8982,6 @@ njs_parser_variable_reference(njs_parser_t *parser, njs_parser_scope_t *scope, vr = &node->u.reference; vr->atom_id = atom_id; - vr->type = type; parse_node.key = atom_id; diff --git a/src/njs_parser.h b/src/njs_parser.h index 1a5cd013..da52dfb2 100644 --- a/src/njs_parser.h +++ b/src/njs_parser.h @@ -40,6 +40,7 @@ struct njs_parser_node_s { uint8_t ctor:1; uint8_t hoist:1; uint8_t array_flat:1; + uint8_t not_defined:1; uint8_t temporary; /* 1 bit */ uint32_t token_line; diff --git a/src/njs_variable.c b/src/njs_variable.c index 7fcaed46..50b13950 100644 --- a/src/njs_variable.c +++ b/src/njs_variable.c @@ -514,14 +514,13 @@ njs_variable_reference(njs_vm_t *vm, njs_parser_node_t *node) if (ref->variable == NULL) { ref->variable = njs_variable_resolve(vm, node); if (njs_slow_path(ref->variable == NULL)) { - ref->not_defined = 1; + node->not_defined = 1; return NULL; } } closure = njs_variable_closure_test(node->scope, ref->variable->scope); - ref->scope = node->scope; ref_node.key = ref->atom_id; diff --git a/src/njs_variable.h b/src/njs_variable.h index db40de75..be1eec68 100644 --- a/src/njs_variable.h +++ b/src/njs_variable.h @@ -43,11 +43,8 @@ typedef enum { typedef struct { - njs_reference_type_t type; uintptr_t atom_id; njs_variable_t *variable; - njs_parser_scope_t *scope; - njs_bool_t not_defined; } njs_variable_reference_t; -- 2.47.3