[njs] Improved njs_vm_compile().

Dmitry Volyntsev xeioex at nginx.com
Wed Feb 20 14:26:02 UTC 2019


details:   https://hg.nginx.org/njs/rev/5db48d70db65
branches:  
changeset: 787:5db48d70db65
user:      hongzhidao <hongzhidao at gmail.com>
date:      Sat Feb 16 23:18:43 2019 +0800
description:
Improved njs_vm_compile().

diffstat:

 njs/njs.c |  17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diffs (48 lines):

diff -r 2101597aa18d -r 5db48d70db65 njs/njs.c
--- a/njs/njs.c	Sat Feb 16 23:18:43 2019 +0800
+++ b/njs/njs.c	Sat Feb 16 23:18:43 2019 +0800
@@ -216,10 +216,11 @@ njs_vm_destroy(njs_vm_t *vm)
 nxt_int_t
 njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
 {
-    nxt_int_t        ret;
-    njs_lexer_t      lexer;
-    njs_parser_t     *parser, *prev;
-    njs_generator_t  generator;
+    nxt_int_t           ret;
+    njs_lexer_t         lexer;
+    njs_parser_t        *parser, *prev;
+    njs_generator_t     generator;
+    njs_parser_scope_t  *scope;
 
     if (vm->parser != NULL && !vm->options.accumulative) {
         return NJS_ERROR;
@@ -254,7 +255,9 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
         goto fail;
     }
 
-    ret = njs_variables_scope_reference(vm, parser->scope);
+    scope = parser->scope;
+
+    ret = njs_variables_scope_reference(vm, scope);
     if (nxt_slow_path(ret != NXT_OK)) {
         goto fail;
     }
@@ -269,7 +272,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
 
     nxt_memzero(&generator, sizeof(njs_generator_t));
 
-    ret = njs_generate_scope(vm, &generator, parser->scope);
+    ret = njs_generate_scope(vm, &generator, scope);
     if (nxt_slow_path(ret != NXT_OK)) {
         goto fail;
     }
@@ -278,7 +281,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
     vm->global_scope = generator.local_scope;
     vm->scope_size = generator.scope_size;
 
-    vm->variables_hash = parser->scope->variables;
+    vm->variables_hash = scope->variables;
 
     if (vm->options.init) {
         ret = njs_vm_init(vm);


More information about the nginx-devel mailing list