From 57d97860dd5f5947af2642a2d8d70af734c7eae4 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 4 Apr 2023 22:17:26 -0700 Subject: [PATCH] VM: removed vm->global_items. --- src/njs_vm.c | 15 ++++++++------- src/njs_vm.h | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/njs_vm.c b/src/njs_vm.c index 4cbd0387..2f684e56 100644 --- a/src/njs_vm.c +++ b/src/njs_vm.c @@ -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; } diff --git a/src/njs_vm.h b/src/njs_vm.h index 48525215..d2b9a1d1 100644 --- a/src/njs_vm.h +++ b/src/njs_vm.h @@ -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; -- 2.47.3