[njs] Refactored functions inlining.

Dmitry Volyntsev xeioex at nginx.com
Tue Jul 2 18:49:17 UTC 2019


details:   https://hg.nginx.org/njs/rev/775430ca2cab
branches:  
changeset: 1026:775430ca2cab
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jul 02 21:37:10 2019 +0300
description:
Refactored functions inlining.

Allowing compiler to decide whether inline a function or not by
removing most of nxt_noinline prefixes.

Inlining simple functions.

Splitting public function getters from njs internal value getters.

diffstat:

 njs/njs.c                 |  164 +++++++++++++++++++++++++++-
 njs/njs_array.c           |  151 +++++++++++--------------
 njs/njs_builtin.c         |   14 +-
 njs/njs_crypto.c          |    4 +-
 njs/njs_date.c            |  101 ++++++++---------
 njs/njs_error.c           |    2 +-
 njs/njs_error.h           |    4 +-
 njs/njs_event.c           |    2 +-
 njs/njs_extern.c          |    2 +-
 njs/njs_fs.c              |   20 +-
 njs/njs_function.c        |   14 +-
 njs/njs_generator.c       |   50 ++++----
 njs/njs_json.c            |   44 +++----
 njs/njs_math.c            |   70 ++++++------
 njs/njs_module.c          |   12 +-
 njs/njs_number.c          |  121 +--------------------
 njs/njs_number.h          |  124 +++++++++++++++++++-
 njs/njs_object.c          |   50 ++------
 njs/njs_object_property.c |   12 +-
 njs/njs_regexp.c          |   14 +-
 njs/njs_string.c          |   66 +++++------
 njs/njs_string.h          |    8 +-
 njs/njs_vm.c              |  264 ++++++++-------------------------------------
 njs/njs_vm.h              |   90 +++++++++++++++
 nxt/nxt_lvlhsh.c          |    2 +-
 25 files changed, 701 insertions(+), 704 deletions(-)

diffs (truncated from 3690 to 1000 lines):

diff -r 0f2d18a5eed3 -r 775430ca2cab njs/njs.c
--- a/njs/njs.c	Tue Jul 02 18:14:47 2019 +0300
+++ b/njs/njs.c	Tue Jul 02 21:37:10 2019 +0300
@@ -663,20 +663,174 @@ njs_vm_add_path(njs_vm_t *vm, const nxt_
 }
 
 
-nxt_noinline njs_value_t *
+njs_value_t *
 njs_vm_retval(njs_vm_t *vm)
 {
     return &vm->retval;
 }
 
 
-nxt_noinline void
+void
 njs_vm_retval_set(njs_vm_t *vm, const njs_value_t *value)
 {
     vm->retval = *value;
 }
 
 
+void
+njs_value_undefined_set(njs_value_t *value)
+{
+    njs_set_undefined(value);
+}
+
+
+void
+njs_value_boolean_set(njs_value_t *value, int yn)
+{
+    njs_set_boolean(value, yn);
+}
+
+
+void
+njs_value_number_set(njs_value_t *value, double num)
+{
+    njs_set_number(value, num);
+}
+
+
+void
+njs_value_data_set(njs_value_t *value, void *data)
+{
+    njs_set_data(value, data);
+}
+
+
+njs_ret_t
+njs_vm_value_string_set(njs_vm_t *vm, njs_value_t *value, const u_char *start,
+    uint32_t size)
+{
+    return njs_string_set(vm, value, start, size);
+}
+
+
+u_char *
+njs_vm_value_string_alloc(njs_vm_t *vm, njs_value_t *value, uint32_t size)
+{
+    return njs_string_alloc(vm, value, size, 0);
+}
+
+
+nxt_noinline void
+njs_vm_value_error_set(njs_vm_t *vm, njs_value_t *value, const char *fmt, ...)
+{
+    va_list  args;
+    u_char   buf[NXT_MAX_ERROR_STR], *p;
+
+    p = buf;
+
+    if (fmt != NULL) {
+        va_start(args, fmt);
+        p = nxt_vsprintf(buf, buf + sizeof(buf), fmt, args);
+        va_end(args);
+    }
+
+    njs_error_new(vm, value, NJS_OBJECT_ERROR, buf, p - buf);
+}
+
+
+uint8_t
+njs_value_bool(const njs_value_t *value)
+{
+    return njs_bool(value);
+}
+
+
+double
+njs_value_number(const njs_value_t *value)
+{
+    return njs_number(value);
+}
+
+
+void *
+njs_value_data(const njs_value_t *value)
+{
+    return njs_data(value);
+}
+
+
+njs_function_t *
+njs_value_function(const njs_value_t *value)
+{
+    return njs_function(value);
+}
+
+
+nxt_int_t
+njs_value_is_null(const njs_value_t *value)
+{
+    return njs_is_null(value);
+}
+
+
+nxt_int_t
+njs_value_is_undefined(const njs_value_t *value)
+{
+    return njs_is_undefined(value);
+}
+
+
+nxt_int_t
+njs_value_is_null_or_undefined(const njs_value_t *value)
+{
+    return njs_is_null_or_undefined(value);
+}
+
+
+nxt_int_t
+njs_value_is_boolean(const njs_value_t *value)
+{
+    return njs_is_boolean(value);
+}
+
+
+nxt_int_t
+njs_value_is_number(const njs_value_t *value)
+{
+    return njs_is_number(value);
+}
+
+
+nxt_int_t
+njs_value_is_valid_number(const njs_value_t *value)
+{
+    return njs_is_number(value)
+           && !isnan(value->data.u.number)
+           && !isinf(value->data.u.number);
+}
+
+
+nxt_int_t
+njs_value_is_string(const njs_value_t *value)
+{
+    return njs_is_string(value);
+}
+
+
+nxt_int_t
+njs_value_is_object(const njs_value_t *value)
+{
+    return njs_is_object(value);
+}
+
+
+nxt_int_t
+njs_value_is_function(const njs_value_t *value)
+{
+    return njs_is_function(value);
+}
+
+
 nxt_noinline void
 njs_vm_memory_error(njs_vm_t *vm)
 {
@@ -770,9 +924,7 @@ njs_vm_object_alloc(njs_vm_t *vm, njs_va
 
     rc = NJS_OK;
 
-    retval->data.u.object = object;
-    retval->type = NJS_OBJECT;
-    retval->data.truth = 1;
+    njs_set_object(retval, object);
 
 done:
 
@@ -797,7 +949,7 @@ njs_vm_object_prop(njs_vm_t *vm, const n
     lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length);
     lhq.proto = &njs_object_hash_proto;
 
-    ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq);
+    ret = nxt_lvlhsh_find(njs_object_hash(value), &lhq);
     if (nxt_slow_path(ret != NXT_OK)) {
         return NULL;
     }
diff -r 0f2d18a5eed3 -r 775430ca2cab njs/njs_array.c
--- a/njs/njs_array.c	Tue Jul 02 18:14:47 2019 +0300
+++ b/njs/njs_array.c	Tue Jul 02 21:37:10 2019 +0300
@@ -118,15 +118,15 @@ static njs_ret_t njs_array_prototype_fin
     njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
 static njs_ret_t njs_array_prototype_map_continuation(njs_vm_t *vm,
     njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
-static nxt_noinline uint32_t njs_array_prototype_map_index(njs_array_t *array,
+static uint32_t njs_array_prototype_map_index(njs_array_t *array,
     njs_array_map_t *map);
-static nxt_noinline njs_ret_t njs_array_iterator_args(njs_vm_t *vm,
+static njs_ret_t njs_array_iterator_args(njs_vm_t *vm,
     njs_value_t *args, nxt_uint_t nargs);
-static nxt_noinline uint32_t njs_array_iterator_index(njs_array_t *array,
+static uint32_t njs_array_iterator_index(njs_array_t *array,
     njs_array_iter_t *iter);
-static nxt_noinline njs_ret_t njs_array_iterator_apply(njs_vm_t *vm,
+static njs_ret_t njs_array_iterator_apply(njs_vm_t *vm,
     njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs);
-static nxt_noinline njs_ret_t njs_array_prototype_find_apply(njs_vm_t *vm,
+static njs_ret_t njs_array_prototype_find_apply(njs_vm_t *vm,
     njs_array_iter_t *iter, njs_value_t *args, nxt_uint_t nargs);
 static njs_ret_t njs_array_prototype_reduce_continuation(njs_vm_t *vm,
     njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
@@ -138,7 +138,7 @@ static njs_ret_t njs_array_prototype_sor
     njs_value_t *args, nxt_uint_t nargs, njs_index_t unused);
 
 
-nxt_noinline njs_array_t *
+njs_array_t *
 njs_array_alloc(njs_vm_t *vm, uint64_t length, uint32_t spare)
 {
     uint64_t     size;
@@ -308,7 +308,6 @@ njs_array_constructor(njs_vm_t *vm, njs_
 
     if (nxt_fast_path(array != NULL)) {
 
-        vm->retval.data.u.array = array;
         value = array->start;
 
         if (args == NULL) {
@@ -326,8 +325,8 @@ njs_array_constructor(njs_vm_t *vm, njs_
             }
         }
 
-        vm->retval.type = NJS_ARRAY;
-        vm->retval.data.truth = 1;
+
+        njs_set_array(&vm->retval, array);
 
         return NXT_OK;
     }
@@ -369,9 +368,7 @@ njs_array_of(njs_vm_t *vm, njs_value_t *
             return NXT_ERROR;
         }
 
-        vm->retval.data.u.array = array;
-        vm->retval.type = NJS_ARRAY;
-        vm->retval.data.truth = 1;
+        njs_set_array(&vm->retval, array);
 
         for (i = 0; i < length; i++) {
             array->start[i] = args[i + 1];
@@ -464,7 +461,7 @@ njs_array_length(njs_vm_t *vm, njs_value
 
         array = (njs_array_t *) proto;
 
-        njs_value_number_set(retval, array->length);
+        njs_set_number(retval, array->length);
         return NJS_OK;
     }
 
@@ -506,7 +503,7 @@ njs_array_length(njs_vm_t *vm, njs_value
 
     array->length = length;
 
-    njs_value_number_set(retval, length);
+    njs_set_number(retval, length);
     return NJS_OK;
 }
 
@@ -619,15 +616,13 @@ njs_array_prototype_slice_copy(njs_vm_t 
         return NXT_ERROR;
     }
 
-    vm->retval.data.u.array = array;
-    vm->retval.type = NJS_ARRAY;
-    vm->retval.data.truth = 1;
+    njs_set_array(&vm->retval, array);
 
     if (length != 0) {
         n = 0;
 
         if (nxt_fast_path(njs_is_array(this))) {
-            value = this->data.u.array->start;
+            value = njs_array_start(this);
 
             do {
                 /* GC: retain long string and object in values[start]. */
@@ -704,7 +699,7 @@ njs_array_prototype_push(njs_vm_t *vm, n
     njs_array_t  *array;
 
     if (njs_is_array(&args[0])) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
 
         if (nargs != 0) {
             ret = njs_array_expand(vm, array, 0, nargs);
@@ -718,7 +713,7 @@ njs_array_prototype_push(njs_vm_t *vm, n
             }
         }
 
-        njs_value_number_set(&vm->retval, array->length);
+        njs_set_number(&vm->retval, array->length);
     }
 
     return NXT_OK;
@@ -735,7 +730,7 @@ njs_array_prototype_pop(njs_vm_t *vm, nj
     retval = &njs_value_undefined;
 
     if (njs_is_array(&args[0])) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
 
         if (array->length != 0) {
             array->length--;
@@ -762,7 +757,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
     njs_array_t  *array;
 
     if (njs_is_array(&args[0])) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
         n = nargs - 1;
 
         if (n != 0) {
@@ -782,7 +777,7 @@ njs_array_prototype_unshift(njs_vm_t *vm
             } while (n > 1);
         }
 
-        njs_value_number_set(&vm->retval, array->length);
+        njs_set_number(&vm->retval, array->length);
     }
 
     return NXT_OK;
@@ -799,7 +794,7 @@ njs_array_prototype_shift(njs_vm_t *vm, 
     retval = &njs_value_undefined;
 
     if (njs_is_array(&args[0])) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
 
         if (array->length != 0) {
             array->length--;
@@ -833,7 +828,7 @@ njs_array_prototype_splice(njs_vm_t *vm,
     delete = 0;
 
     if (njs_is_array(&args[0])) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
         length = array->length;
 
         if (nargs > 1) {
@@ -913,9 +908,7 @@ njs_array_prototype_splice(njs_vm_t *vm,
         }
     }
 
-    vm->retval.data.u.array = deleted;
-    vm->retval.type = NJS_ARRAY;
-    vm->retval.data.truth = 1;
+    njs_set_array(&vm->retval, deleted);
 
     return NXT_OK;
 }
@@ -930,7 +923,7 @@ njs_array_prototype_reverse(njs_vm_t *vm
     njs_array_t  *array;
 
     if (njs_is_array(&args[0])) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
         length = array->length;
 
         if (length > 1) {
@@ -941,9 +934,7 @@ njs_array_prototype_reverse(njs_vm_t *vm
             }
         }
 
-        vm->retval.data.u.array = array;
-        vm->retval.type = NJS_ARRAY;
-        vm->retval.data.truth = 1;
+        njs_set_array(&vm->retval, array);
 
     } else {
         /* STUB */
@@ -991,7 +982,7 @@ njs_array_prototype_join(njs_vm_t *vm, n
         goto empty;
     }
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
 
     if (array->length == 0) {
         goto empty;
@@ -1076,7 +1067,7 @@ njs_array_prototype_join_continuation(nj
     n = 0;
     mask = -1;
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
 
     for (i = 0; i < array->length; i++) {
         value = &array->start[i];
@@ -1168,7 +1159,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
 
     for (i = 0; i < nargs; i++) {
         if (njs_is_array(&args[i])) {
-            length += args[i].data.u.array->length;
+            length += njs_array_len(&args[i]);
 
         } else {
             length++;
@@ -1180,9 +1171,7 @@ njs_array_prototype_concat(njs_vm_t *vm,
         return NXT_ERROR;
     }
 
-    vm->retval.data.u.array = array;
-    vm->retval.type = NJS_ARRAY;
-    vm->retval.data.truth = 1;
+    njs_set_array(&vm->retval, array);
 
     value = array->start;
 
@@ -1202,8 +1191,8 @@ njs_array_copy(njs_value_t *dst, njs_val
     n = 1;
 
     if (njs_is_array(src)) {
-        n = src->data.u.array->length;
-        src = src->data.u.array->start;
+        n = njs_array_len(src);
+        src = njs_array_start(src);
     }
 
     while (n != 0) {
@@ -1230,7 +1219,7 @@ njs_array_prototype_index_of(njs_vm_t *v
         goto done;
     }
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
     length = array->length;
 
     if (length == 0) {
@@ -1270,7 +1259,7 @@ njs_array_prototype_index_of(njs_vm_t *v
 
 done:
 
-    njs_value_number_set(&vm->retval, index);
+    njs_set_number(&vm->retval, index);
 
     return NXT_OK;
 }
@@ -1290,7 +1279,7 @@ njs_array_prototype_last_index_of(njs_vm
         goto done;
     }
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
     length = array->length;
 
     if (length == 0) {
@@ -1329,7 +1318,7 @@ njs_array_prototype_last_index_of(njs_vm
 
 done:
 
-    njs_value_number_set(&vm->retval, index);
+    njs_set_number(&vm->retval, index);
 
     return NXT_OK;
 }
@@ -1350,7 +1339,7 @@ njs_array_prototype_includes(njs_vm_t *v
         goto done;
     }
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
     length = array->length;
 
     if (length == 0) {
@@ -1480,7 +1469,7 @@ njs_array_prototype_fill_continuation(nj
     fill = njs_vm_continuation(vm);
 
     if (njs_is_array(this)) {
-        array = this->data.u.array;
+        array = njs_array(this);
         length = array->length;
 
     } else {
@@ -1584,7 +1573,7 @@ njs_array_prototype_for_each_continuatio
 
     iter = njs_vm_continuation(vm);
 
-    index = njs_array_iterator_index(args[0].data.u.array, iter);
+    index = njs_array_iterator_index(njs_array(&args[0]), iter);
 
     if (index == NJS_ARRAY_INVALID_INDEX) {
         vm->retval = njs_value_undefined;
@@ -1628,7 +1617,7 @@ njs_array_prototype_some_continuation(nj
         retval = &njs_value_true;
 
     } else {
-        index = njs_array_iterator_index(args[0].data.u.array, iter);
+        index = njs_array_iterator_index(njs_array(&args[0]), iter);
 
         if (index == NJS_ARRAY_INVALID_INDEX) {
             retval = &njs_value_false;
@@ -1678,7 +1667,7 @@ njs_array_prototype_every_continuation(n
         retval = &njs_value_false;
 
     } else {
-        index = njs_array_iterator_index(args[0].data.u.array, iter);
+        index = njs_array_iterator_index(njs_array(&args[0]), iter);
 
         if (index == NJS_ARRAY_INVALID_INDEX) {
             retval = &njs_value_true;
@@ -1736,13 +1725,11 @@ njs_array_prototype_filter_continuation(
         }
     }
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
     index = njs_array_iterator_index(array, &filter->iter);
 
     if (index == NJS_ARRAY_INVALID_INDEX) {
-        vm->retval.data.u.array = filter->array;
-        vm->retval.type = NJS_ARRAY;
-        vm->retval.data.truth = 1;
+        njs_set_array(&vm->retval, filter->array);
 
         return NXT_OK;
     }
@@ -1788,7 +1775,7 @@ njs_array_prototype_find_continuation(nj
     iter = &find->iter;
 
     if (!njs_is_true(&iter->retval)) {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
         iter->index++;
 
         if (iter->index < iter->length && iter->index < array->length) {
@@ -1843,7 +1830,7 @@ njs_array_prototype_find_index_continuat
         iter->index++;
 
         if (iter->index < iter->length
-            && iter->index < args[0].data.u.array->length)
+            && iter->index < njs_array_len(&args[0]))
         {
             return njs_array_prototype_find_apply(vm, iter, args, nargs);
         }
@@ -1851,13 +1838,13 @@ njs_array_prototype_find_index_continuat
         index = -1;
     }
 
-    njs_value_number_set(&vm->retval, index);
+    njs_set_number(&vm->retval, index);
 
     return NXT_OK;
 }
 
 
-static nxt_noinline njs_ret_t
+static njs_ret_t
 njs_array_prototype_find_apply(njs_vm_t *vm, njs_array_iter_t *iter,
     njs_value_t *args, nxt_uint_t nargs)
 {
@@ -1871,7 +1858,7 @@ njs_array_prototype_find_apply(njs_vm_t 
     arguments[0] = *value;
 
     n = iter->index;
-    value = &args[0].data.u.array->start[n];
+    value = &njs_array_start(&args[0])[n];
 
     if (!njs_is_valid(value)) {
         value = &njs_value_undefined;
@@ -1879,7 +1866,7 @@ njs_array_prototype_find_apply(njs_vm_t 
 
     arguments[1] = *value;
 
-    njs_value_number_set(&arguments[2], n);
+    njs_set_number(&arguments[2], n);
 
     arguments[3] = args[0];
 
@@ -1904,7 +1891,7 @@ njs_array_prototype_map(njs_vm_t *vm, nj
     map->iter.u.cont.function = njs_array_prototype_map_continuation;
     njs_set_invalid(&map->iter.retval);
 
-    map->array = njs_array_alloc(vm, args[0].data.u.array->length, 0);
+    map->array = njs_array_alloc(vm, njs_array_len(&args[0]), 0);
     if (nxt_slow_path(map->array == NULL)) {
         return NXT_ERROR;
     }
@@ -1913,7 +1900,7 @@ njs_array_prototype_map(njs_vm_t *vm, nj
 }
 
 
-static nxt_noinline njs_ret_t
+static njs_ret_t
 njs_array_prototype_map_continuation(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused)
 {
@@ -1926,12 +1913,10 @@ njs_array_prototype_map_continuation(njs
         map->array->start[map->iter.index] = map->iter.retval;
     }
 
-    index = njs_array_prototype_map_index(args[0].data.u.array, map);
+    index = njs_array_prototype_map_index(njs_array(&args[0]), map);
 
     if (index == NJS_ARRAY_INVALID_INDEX) {
-        vm->retval.data.u.array = map->array;
-        vm->retval.type = NJS_ARRAY;
-        vm->retval.data.truth = 1;
+        njs_set_array(&vm->retval, map->array);
 
         return NXT_OK;
     }
@@ -1987,7 +1972,7 @@ njs_array_prototype_reduce(njs_vm_t *vm,
         iter->retval = args[2];
 
     } else {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
         n = njs_array_iterator_index(array, iter);
 
         if (n == NJS_ARRAY_INVALID_INDEX) {
@@ -2012,7 +1997,7 @@ njs_array_prototype_reduce_continuation(
     njs_array_iter_t  *iter;
 
     iter = njs_vm_continuation(vm);
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
 
     n = njs_array_iterator_index(array, iter);
 
@@ -2028,7 +2013,7 @@ njs_array_prototype_reduce_continuation(
 
     arguments[2] = array->start[n];
 
-    njs_value_number_set(&arguments[3], n);
+    njs_set_number(&arguments[3], n);
 
     arguments[4] = args[0];
 
@@ -2037,7 +2022,7 @@ njs_array_prototype_reduce_continuation(
 }
 
 
-static nxt_noinline njs_ret_t
+static njs_ret_t
 njs_array_iterator_args(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs)
 {
     njs_array_iter_t  *iter;
@@ -2045,7 +2030,7 @@ njs_array_iterator_args(njs_vm_t *vm, nj
     if (nargs > 1 && njs_is_array(&args[0]) && njs_is_function(&args[1])) {
 
         iter = njs_vm_continuation(vm);
-        iter->length = args[0].data.u.array->length;
+        iter->length = njs_array_len(&args[0]);
         iter->retval.data.truth = 0;
         iter->index = NJS_ARRAY_INVALID_INDEX;
 
@@ -2058,7 +2043,7 @@ njs_array_iterator_args(njs_vm_t *vm, nj
 }
 
 
-static nxt_noinline uint32_t
+static uint32_t
 njs_array_iterator_index(njs_array_t *array, njs_array_iter_t *iter)
 {
     uint32_t  i, length;
@@ -2076,7 +2061,7 @@ njs_array_iterator_index(njs_array_t *ar
 }
 
 
-static nxt_noinline njs_ret_t
+static njs_ret_t
 njs_array_iterator_apply(njs_vm_t *vm, njs_array_iter_t *iter,
     njs_value_t *args, nxt_uint_t nargs)
 {
@@ -2090,9 +2075,9 @@ njs_array_iterator_apply(njs_vm_t *vm, n
     arguments[0] = *value;
 
     n = iter->index;
-    arguments[1] = args[0].data.u.array->start[n];
-
-    njs_value_number_set(&arguments[2], n);
+    arguments[1] = njs_array_start(&args[0])[n];
+
+    njs_set_number(&arguments[2], n);
 
     arguments[3] = args[0];
 
@@ -2122,7 +2107,7 @@ njs_array_prototype_reduce_right(njs_vm_
         iter->retval = args[2];
 
     } else {
-        array = args[0].data.u.array;
+        array = njs_array(&args[0]);
         n = njs_array_reduce_right_index(array, iter);
 
         if (n == NJS_ARRAY_INVALID_INDEX) {
@@ -2139,7 +2124,7 @@ njs_array_prototype_reduce_right(njs_vm_
 }
 
 
-static nxt_noinline njs_ret_t
+static njs_ret_t
 njs_array_prototype_reduce_right_continuation(njs_vm_t *vm, njs_value_t *args,
     nxt_uint_t nargs, njs_index_t unused)
 {
@@ -2149,7 +2134,7 @@ njs_array_prototype_reduce_right_continu
     njs_array_iter_t  *iter;
 
     iter = njs_vm_continuation(vm);
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
 
     n = njs_array_reduce_right_index(array, iter);
 
@@ -2165,7 +2150,7 @@ njs_array_prototype_reduce_right_continu
 
     arguments[2] = array->start[n];
 
-    njs_value_number_set(&arguments[3], n);
+    njs_set_number(&arguments[3], n);
 
     arguments[4] = args[0];
 
@@ -2174,7 +2159,7 @@ njs_array_prototype_reduce_right_continu
 }
 
 
-static nxt_noinline uint32_t
+static uint32_t
 njs_array_reduce_right_index(njs_array_t *array, njs_array_iter_t *iter)
 {
     uint32_t  n;
@@ -2212,7 +2197,7 @@ njs_array_string_sort(njs_vm_t *vm, njs_
 
     ret = njs_string_cmp(&args[1], &args[2]);
 
-    njs_value_number_set(&vm->retval, ret);
+    njs_set_number(&vm->retval, ret);
 
     return NXT_OK;
 }
@@ -2234,7 +2219,7 @@ njs_array_prototype_sort(njs_vm_t *vm, n
 {
     njs_array_sort_t  *sort;
 
-    if (njs_is_array(&args[0]) && args[0].data.u.array->length > 1) {
+    if (njs_is_array(&args[0]) && njs_array_len(&args[0]) > 1) {
 
         sort = njs_vm_continuation(vm);
         sort->u.cont.function = njs_array_prototype_sort_continuation;
@@ -2266,7 +2251,7 @@ njs_array_prototype_sort_continuation(nj
     njs_value_t       value, *start, arguments[3];
     njs_array_sort_t  *sort;
 
-    array = args[0].data.u.array;
+    array = njs_array(&args[0]);
     start = array->start;
 
     sort = njs_vm_continuation(vm);
diff -r 0f2d18a5eed3 -r 775430ca2cab njs/njs_builtin.c
--- a/njs/njs_builtin.c	Tue Jul 02 18:14:47 2019 +0300
+++ b/njs/njs_builtin.c	Tue Jul 02 21:37:10 2019 +0300
@@ -840,7 +840,7 @@ njs_vm_expression_completions(njs_vm_t *
         lhq.key.length = p - lhq.key.start;
         lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length);
 
-        ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq);
+        ret = nxt_lvlhsh_find(njs_object_hash(value), &lhq);
         if (nxt_slow_path(ret != NXT_OK)) {
             return NULL;
         }
@@ -1178,9 +1178,7 @@ njs_process_object_argv(njs_vm_t *vm, nj
         return NJS_ERROR;
     }
 
-    prop->value.data.u.array = argv;
-    prop->value.type = NJS_ARRAY;
-    prop->value.data.truth = 1;
+    njs_set_array(&prop->value, argv);
 
     lhq.value = prop;
     lhq.key_hash = NJS_ARGV_HASH;
@@ -1189,7 +1187,7 @@ njs_process_object_argv(njs_vm_t *vm, nj
     lhq.pool = vm->mem_pool;
     lhq.proto = &njs_object_hash_proto;
 
-    ret = nxt_lvlhsh_insert(&process->data.u.object->hash, &lhq);
+    ret = nxt_lvlhsh_insert(njs_object_hash(process), &lhq);
 
     if (nxt_fast_path(ret == NXT_OK)) {
         *retval = prop->value;
@@ -1281,9 +1279,7 @@ njs_process_object_env(njs_vm_t *vm, njs
         return NXT_ERROR;
     }
 
-    prop->value.data.u.object = env;
-    prop->value.type = NJS_OBJECT;
-    prop->value.data.truth = 1;
+    njs_set_object(&prop->value, env);
 
     lhq.replace = 0;
     lhq.pool = vm->mem_pool;
@@ -1292,7 +1288,7 @@ njs_process_object_env(njs_vm_t *vm, njs
     lhq.key = nxt_string_value("env");
     lhq.key_hash = NJS_ENV_HASH;
 
-    ret = nxt_lvlhsh_insert(&process->data.u.object->hash, &lhq);
+    ret = nxt_lvlhsh_insert(njs_object_hash(process), &lhq);
 
     if (nxt_fast_path(ret == NXT_OK)) {
         *retval = prop->value;
diff -r 0f2d18a5eed3 -r 775430ca2cab njs/njs_crypto.c
--- a/njs/njs_crypto.c	Tue Jul 02 18:14:47 2019 +0300
+++ b/njs/njs_crypto.c	Tue Jul 02 21:37:10 2019 +0300
@@ -186,7 +186,7 @@ njs_crypto_create_hash(njs_vm_t *vm, njs
 
     alg->init(&dgst->u);
 
-    njs_value_data_set(&hash->value, dgst);
+    njs_set_data(&hash->value, dgst);
 
     vm->retval.data.u.object_value = hash;
     vm->retval.type = NJS_OBJECT_VALUE;
@@ -452,7 +452,7 @@ njs_crypto_create_hmac(njs_vm_t *vm, njs
         return NJS_ERROR;
     }
 
-    njs_value_data_set(&hmac->value, ctx);
+    njs_set_data(&hmac->value, ctx);
 
     vm->retval.data.u.object_value = hmac;
     vm->retval.type = NJS_OBJECT_VALUE;
diff -r 0f2d18a5eed3 -r 775430ca2cab njs/njs_date.c
--- a/njs/njs_date.c	Tue Jul 02 18:14:47 2019 +0300
+++ b/njs/njs_date.c	Tue Jul 02 21:37:10 2019 +0300
@@ -23,32 +23,29 @@
     sizeof("Mon Sep 28 1970 12:00:00 GMT+0600 (XXXXX)")
 
 
-static nxt_noinline double njs_date_string_parse(njs_value_t *date);
+static double njs_date_string_parse(njs_value_t *date);
 static double njs_date_rfc2822_string_parse(struct tm *tm, const u_char *p,
     const u_char *end);
 static double njs_date_js_string_parse(struct tm *tm, const u_char *p,
     const u_char *end);
 static const u_char *njs_date_skip_week_day(const u_char *p, const u_char *end);
 static const u_char *njs_date_skip_spaces(const u_char *p, const u_char *end);
-static nxt_noinline nxt_int_t njs_date_month_parse(const u_char *p,
-    const u_char *end);
-static nxt_noinline const u_char *njs_date_time_parse(struct tm *tm,
-    const u_char *p, const u_char *end);
-static nxt_noinline nxt_int_t njs_date_gmtoff_parse(const u_char *start,
+static nxt_int_t njs_date_month_parse(const u_char *p, const u_char *end);
+static const u_char *njs_date_time_parse(struct tm *tm, const u_char *p,
     const u_char *end);
-static nxt_noinline const u_char *njs_date_number_parse(int *value,
-    const u_char *p, const u_char *end, size_t size);
+static nxt_int_t njs_date_gmtoff_parse(const u_char *start, const u_char *end);
+static const u_char *njs_date_number_parse(int *value, const u_char *p,
+    const u_char *end, size_t size);
 static int64_t njs_timegm(struct tm *tm);
-static nxt_noinline njs_ret_t njs_date_string(njs_vm_t *vm, const char *fmt,
-    double time);
-static nxt_noinline double njs_date_time(struct tm *tm, int64_t ms);
+static njs_ret_t njs_date_string(njs_vm_t *vm, const char *fmt, double time);
+static double njs_date_time(struct tm *tm, int64_t ms);
 static double njs_date_utc_time(struct tm *tm, double time);
 
 
 static const njs_value_t  njs_string_invalid_date = njs_string("Invalid Date");
 
 
-static nxt_noinline uint64_t
+static uint64_t
 njs_gettime(void)
 {
     struct timeval  tv;
@@ -59,7 +56,7 @@ njs_gettime(void)
 }
 
 
-static nxt_noinline double
+static double
 njs_timeclip(double time)
 {
     if (isinf(time) || isnan(time) || fabs(time) > 8.64e15) {
@@ -219,7 +216,7 @@ njs_date_utc(njs_vm_t *vm, njs_value_t *
 
 done:
 
-    njs_value_number_set(&vm->retval, time);
+    njs_set_number(&vm->retval, time);
 
     return NXT_OK;
 }
@@ -278,7 +275,7 @@ static njs_ret_t
 njs_date_now(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    njs_value_number_set(&vm->retval, njs_gettime());
+    njs_set_number(&vm->retval, njs_gettime());
 
     return NXT_OK;
 }
@@ -297,13 +294,13 @@ njs_date_parse(njs_vm_t *vm, njs_value_t
         time = NAN;
     }
 
-    njs_value_number_set(&vm->retval, time);
+    njs_set_number(&vm->retval, time);
 
     return NXT_OK;
 }
 
 
-static nxt_noinline double
+static double
 njs_date_string_parse(njs_value_t *date)
 {
     int                ext, ms, ms_length, skipped;
@@ -704,7 +701,7 @@ njs_date_skip_spaces(const u_char *p, co
 }
 
 
-static nxt_noinline nxt_int_t
+static nxt_int_t
 njs_date_month_parse(const u_char *p, const u_char *end)
 {
     if (p + 2 < end) {
@@ -792,7 +789,7 @@ njs_date_month_parse(const u_char *p, co
 }
 
 
-static nxt_noinline const u_char *
+static const u_char *
 njs_date_time_parse(struct tm *tm, const u_char *p, const u_char *end)
 {
     p = njs_date_number_parse(&tm->tm_hour, p, end, 2);
@@ -821,7 +818,7 @@ njs_date_time_parse(struct tm *tm, const
 }
 
 
-static nxt_noinline nxt_int_t
+static nxt_int_t
 njs_date_gmtoff_parse(const u_char *start, const u_char *end)
 {
     int           gmtoff, hour, min;
@@ -852,7 +849,7 @@ njs_date_gmtoff_parse(const u_char *star
 }
 
 
-static nxt_noinline const u_char *
+static const u_char *
 njs_date_number_parse(int *value, const u_char *p, const u_char *end,
     size_t size)
 {
@@ -950,7 +947,7 @@ static njs_ret_t
 njs_date_prototype_value_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     njs_index_t unused)
 {
-    njs_value_number_set(&vm->retval, args[0].data.u.date->time);
+    njs_set_number(&vm->retval, args[0].data.u.date->time);
 
     return NXT_OK;
 }
@@ -981,7 +978,7 @@ njs_date_prototype_to_time_string(njs_vm
 }
 
 
-static nxt_noinline njs_ret_t
+static njs_ret_t
 njs_date_string(njs_vm_t *vm, const char *fmt, double time)
 {
     size_t     size;
@@ -1097,7 +1094,7 @@ njs_date_prototype_get_full_year(njs_vm_
         value = tm.tm_year + 1900;
     }
 
-    njs_value_number_set(&vm->retval, value);
+    njs_set_number(&vm->retval, value);
 
     return NXT_OK;
 }
@@ -1120,7 +1117,7 @@ njs_date_prototype_get_utc_full_year(njs
         value = tm.tm_year + 1900;
     }
 


More information about the nginx-devel mailing list