[njs] Refactored out njs_function_apply().

Dmitry Volyntsev xeioex at nginx.com
Thu Jan 10 16:00:52 UTC 2019


details:   https://hg.nginx.org/njs/rev/7029ec713458
branches:  
changeset: 722:7029ec713458
user:      hongzhidao <hongzhidao at gmail.com>
date:      Tue Jan 08 06:14:36 2019 +0800
description:
Refactored out njs_function_apply().

As a variant of njs_function_activate().

diffstat:

 njs/njs_function.c |  42 +++---------------------------------------
 njs/njs_function.h |  13 ++++++++++---
 2 files changed, 13 insertions(+), 42 deletions(-)

diffs (96 lines):

diff -r d357ff6b4fe3 -r 7029ec713458 njs/njs_function.c
--- a/njs/njs_function.c	Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_function.c	Tue Jan 08 06:14:36 2019 +0800
@@ -393,42 +393,6 @@ njs_function_frame_alloc(njs_vm_t *vm, s
 
 
 nxt_noinline njs_ret_t
-njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
-    nxt_uint_t nargs, njs_index_t retval)
-{
-    njs_ret_t           ret;
-    njs_continuation_t  *cont;
-
-    if (function->native) {
-        ret = njs_function_native_frame(vm, function, &args[0], &args[1],
-                                        nargs - 1, NJS_CONTINUATION_SIZE, 0);
-        if (ret != NJS_OK) {
-            return ret;
-        }
-
-        cont = njs_vm_continuation(vm);
-
-        cont->function = function->u.native;
-        cont->args_types = function->args_types;
-        cont->retval = retval;
-
-        cont->return_address = vm->current;
-        vm->current = (u_char *) njs_continuation_nexus;
-
-        return NJS_APPLIED;
-    }
-
-    ret = njs_function_frame(vm, function, &args[0], &args[1], nargs - 1, 0);
-
-    if (nxt_fast_path(ret == NXT_OK)) {
-        return njs_function_call(vm, retval, 0);
-    }
-
-    return ret;
-}
-
-
-nxt_noinline njs_ret_t
 njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
 {
     size_t                 size;
@@ -978,9 +942,9 @@ njs_function_prototype_apply(njs_vm_t *v
 
 
 njs_ret_t
-njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
-    const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval,
-    size_t advance)
+njs_function_activate(njs_vm_t *vm, njs_function_t *function,
+    const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+    njs_index_t retval, size_t advance)
 {
     njs_ret_t           ret;
     njs_continuation_t  *cont;
diff -r d357ff6b4fe3 -r 7029ec713458 njs/njs_function.h
--- a/njs/njs_function.h	Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_function.h	Tue Jan 08 06:14:36 2019 +0800
@@ -162,8 +162,6 @@ njs_value_t *njs_function_property_proto
     njs_value_t *value);
 njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused);
-njs_ret_t njs_function_apply(njs_vm_t *vm, njs_function_t *function,
-    njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
 njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
     const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
     size_t reserve, nxt_bool_t ctor);
@@ -171,7 +169,7 @@ njs_ret_t njs_function_frame(njs_vm_t *v
     const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
     nxt_bool_t ctor);
 njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
-    njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+    const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
     njs_index_t retval, size_t advance);
 njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
 njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
@@ -180,6 +178,15 @@ njs_ret_t njs_function_native_call(njs_v
 void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
 
 
+nxt_inline njs_ret_t
+njs_function_apply(njs_vm_t *vm, njs_function_t *function,
+    const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
+{
+    return njs_function_activate(vm, function, &args[0], &args[1], nargs - 1,
+                                 retval, 0);
+}
+
+
 nxt_inline njs_native_frame_t *
 njs_function_previous_frame(njs_native_frame_t *frame)
 {


More information about the nginx-devel mailing list