[njs] Allocating njs_generator_t on stack.
Dmitry Volyntsev
xeioex at nginx.com
Wed Feb 20 14:26:01 UTC 2019
details: https://hg.nginx.org/njs/rev/68e7119e97fe
branches:
changeset: 785:68e7119e97fe
user: hongzhidao <hongzhidao at gmail.com>
date: Sat Feb 16 23:18:43 2019 +0800
description:
Allocating njs_generator_t on stack.
diffstat:
njs/njs.c | 30 +++++++++++-------------------
njs/njs_generator.c | 27 +++++++++------------------
2 files changed, 20 insertions(+), 37 deletions(-)
diffs (109 lines):
diff -r b23c0a90e37f -r 68e7119e97fe 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,20 +216,20 @@ 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;
+ nxt_int_t ret;
njs_lexer_t *lexer;
njs_parser_t *parser, *prev;
- njs_generator_t *generator;
+ njs_generator_t generator;
+
+ if (vm->parser != NULL && !vm->options.accumulative) {
+ return NJS_ERROR;
+ }
parser = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_parser_t));
if (nxt_slow_path(parser == NULL)) {
return NJS_ERROR;
}
- if (vm->parser != NULL && !vm->options.accumulative) {
- return NJS_ERROR;
- }
-
prev = vm->parser;
vm->parser = parser;
@@ -269,24 +269,16 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
*/
vm->code = NULL;
- generator = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t),
- sizeof(njs_generator_t));
+ nxt_memzero(&generator, sizeof(njs_generator_t));
- if (nxt_slow_path(generator == NULL)) {
- goto fail;
- }
-
- nxt_memzero(generator, sizeof(njs_generator_t));
-
- ret = njs_generate_scope(vm, generator, parser->scope);
+ ret = njs_generate_scope(vm, &generator, parser->scope);
if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}
- vm->current = generator->code_start;
-
- vm->global_scope = generator->local_scope;
- vm->scope_size = generator->scope_size;
+ vm->current = generator.code_start;
+ vm->global_scope = generator.local_scope;
+ vm->scope_size = generator.scope_size;
vm->variables_hash = parser->scope->variables;
diff -r b23c0a90e37f -r 68e7119e97fe njs/njs_generator.c
--- a/njs/njs_generator.c Sat Feb 16 23:18:43 2019 +0800
+++ b/njs/njs_generator.c Sat Feb 16 23:18:43 2019 +0800
@@ -2282,19 +2282,13 @@ njs_generate_function_scope(njs_vm_t *vm
size_t size;
nxt_int_t ret;
nxt_array_t *closure;
- njs_generator_t *generator;
-
- generator = nxt_mp_align(vm->mem_pool, sizeof(njs_value_t),
- sizeof(njs_generator_t));
- if (nxt_slow_path(generator == NULL)) {
- return NXT_ERROR;
- }
-
- nxt_memzero(generator, sizeof(njs_generator_t));
+ njs_generator_t generator;
node = node->right;
- ret = njs_generate_scope(vm, generator, node->scope);
+ nxt_memzero(&generator, sizeof(njs_generator_t));
+
+ ret = njs_generate_scope(vm, &generator, node->scope);
if (nxt_fast_path(ret == NXT_OK)) {
size = 0;
@@ -2309,16 +2303,13 @@ njs_generate_function_scope(njs_vm_t *vm
lambda->closure_size = size;
lambda->nesting = node->scope->nesting;
- lambda->arguments_object = generator->arguments_object;
-
- lambda->local_size = generator->scope_size;
- lambda->local_scope = generator->local_scope;
-
- lambda->start = generator->code_start;
+ lambda->arguments_object = generator.arguments_object;
+
+ lambda->start = generator.code_start;
+ lambda->local_size = generator.scope_size;
+ lambda->local_scope = generator.local_scope;
}
- nxt_mp_free(vm->mem_pool, generator);
-
return ret;
}
More information about the nginx-devel
mailing list