]> git.kaiwu.me - njs.git/commitdiff
VM: removed vm->global_items.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 5 Apr 2023 05:17:26 +0000 (22:17 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 5 Apr 2023 05:17:26 +0000 (22:17 -0700)
src/njs_vm.c
src/njs_vm.h

index 4cbd0387ddc3fdce37e65939e016387134156ccb..2f684e56fdd099091310ed19d6bf6326accf941d 100644 (file)
@@ -145,6 +145,7 @@ njs_vm_destroy(njs_vm_t *vm)
 njs_int_t
 njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
 {
+    size_t              global_items;
     njs_int_t           ret;
     njs_str_t           ast;
     njs_chb_t           chain;
@@ -156,6 +157,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
 
     vm->codes = NULL;
 
+    global_items = (vm->global_scope != NULL) ? vm->global_scope->items : 0;
+
     ret = njs_parser_init(vm, &parser, vm->global_scope, &vm->options.file,
                           *start, end, 0);
     if (njs_slow_path(ret != NJS_OK)) {
@@ -202,9 +205,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
         return NJS_ERROR;
     }
 
-    vm->global_scope = scope;
-
-    if (scope->items > vm->global_items) {
+    if (scope->items > global_items) {
         global = vm->levels[NJS_LEVEL_GLOBAL];
 
         new = njs_scope_make(vm, scope->items);
@@ -215,8 +216,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
         vm->levels[NJS_LEVEL_GLOBAL] = new;
 
         if (global != NULL) {
-            while (vm->global_items != 0) {
-                vm->global_items--;
+            while (global_items != 0) {
+                global_items--;
 
                 *new++ = *global++;
             }
@@ -228,7 +229,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
 
     vm->start = generator.code_start;
     vm->variables_hash = &scope->variables;
-    vm->global_items = scope->items;
+    vm->global_scope = scope;
 
     if (vm->options.disassemble) {
         njs_disassembler(vm);
@@ -351,7 +352,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external)
         goto fail;
     }
 
-    global = njs_scope_make(nvm, nvm->global_items);
+    global = njs_scope_make(nvm, nvm->global_scope->items);
     if (njs_slow_path(global == NULL)) {
         goto fail;
     }
index 485252150a42a53b0d3cdcbe8a2ac6790ad149a7..d2b9a1d148228ee030ff281ad2609759c87edd63 100644 (file)
@@ -126,7 +126,6 @@ struct njs_vm_s {
 
     njs_arr_t                *scope_absolute;
     njs_value_t              **levels[NJS_LEVEL_MAX];
-    size_t                   global_items;
 
     njs_external_ptr_t       external;