[njs] Introduced njs_array_push().

Dmitry Volyntsev xeioex at nginx.com
Tue Jun 9 16:48:19 UTC 2020


details:   https://hg.nginx.org/njs/rev/724dedc6be18
branches:  
changeset: 1428:724dedc6be18
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jun 09 12:56:56 2020 +0000
description:
Introduced njs_array_push().

diffstat:

 src/njs_array.h |  14 ++++++++++++++
 src/njs_vm.c    |  12 +-----------
 2 files changed, 15 insertions(+), 11 deletions(-)

diffs (51 lines):

diff -r 857c2166d10b -r 724dedc6be18 src/njs_array.h
--- a/src/njs_array.h	Sat Jun 06 18:15:07 2020 +0300
+++ b/src/njs_array.h	Tue Jun 09 12:56:56 2020 +0000
@@ -35,6 +35,20 @@ njs_int_t njs_array_prototype_to_string(
     njs_uint_t nargs, njs_index_t unused);
 
 
+njs_inline njs_value_t *
+njs_array_push(njs_vm_t *vm, njs_array_t *array)
+{
+    njs_int_t  ret;
+
+    ret = njs_array_expand(vm, array, 0, 1);
+    if (njs_slow_path(ret != NJS_OK)) {
+        return NULL;
+    }
+
+    return &array->start[array->length++];
+}
+
+
 extern const njs_object_init_t  njs_array_instance_init;
 extern const njs_object_type_init_t  njs_array_type_init;
 
diff -r 857c2166d10b -r 724dedc6be18 src/njs_vm.c
--- a/src/njs_vm.c	Sat Jun 06 18:15:07 2020 +0300
+++ b/src/njs_vm.c	Tue Jun 09 12:56:56 2020 +0000
@@ -934,22 +934,12 @@ njs_vm_array_alloc(njs_vm_t *vm, njs_val
 njs_value_t *
 njs_vm_array_push(njs_vm_t *vm, njs_value_t *value)
 {
-    njs_int_t    ret;
-    njs_array_t  *array;
-
     if (njs_slow_path(!njs_is_array(value))) {
         njs_type_error(vm, "njs_vm_array_push() argument is not array");
         return NULL;
     }
 
-    array = njs_array(value);
-
-    ret = njs_array_expand(vm, array, 0, 1);
-    if (njs_slow_path(ret != NJS_OK)) {
-        return NULL;
-    }
-
-    return &array->start[array->length++];
+    return njs_array_push(vm, njs_array(value));
 }
 
 


More information about the nginx-devel mailing list