[njs] Making njs_value_property_i64() and njs_value_property_i64_set() fast.

Dmitry Volyntsev xeioex at nginx.com
Wed Jan 12 18:00:09 UTC 2022


details:   https://hg.nginx.org/njs/rev/2adc0d3fc2bd
branches:  
changeset: 1801:2adc0d3fc2bd
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Jan 12 17:58:19 2022 +0000
description:
Making njs_value_property_i64() and njs_value_property_i64_set() fast.

Since f5afb325896f (0.3.9) njs_value_property() and
njs_value_property_set() have fast paths when key is a number.

Passing key as a number eliminates conversion index to string and back.

diffstat:

 src/njs_value.h |  12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)

diffs (33 lines):

diff -r c786ef848004 -r 2adc0d3fc2bd src/njs_value.h
--- a/src/njs_value.h	Wed Jan 12 17:58:18 2022 +0000
+++ b/src/njs_value.h	Wed Jan 12 17:58:19 2022 +0000
@@ -1080,13 +1080,9 @@ njs_inline njs_int_t
 njs_value_property_i64(njs_vm_t *vm, njs_value_t *value, int64_t index,
     njs_value_t *retval)
 {
-    njs_int_t    ret;
     njs_value_t  key;
 
-    ret = njs_int64_to_string(vm, &key, index);
-    if (njs_slow_path(ret != NJS_OK)) {
-        return ret;
-    }
+    njs_set_number(&key, index);
 
     return njs_value_property(vm, value, &key, retval);
 }
@@ -1096,13 +1092,9 @@ njs_inline njs_int_t
 njs_value_property_i64_set(njs_vm_t *vm, njs_value_t *value, int64_t index,
     njs_value_t *setval)
 {
-    njs_int_t    ret;
     njs_value_t  key;
 
-    ret = njs_int64_to_string(vm, &key, index);
-    if (njs_slow_path(ret != NJS_OK)) {
-        return ret;
-    }
+    njs_set_number(&key, index);
 
     return njs_value_property_set(vm, value, &key, setval);
 }



More information about the nginx-devel mailing list