]> git.kaiwu.me - njs.git/commitdiff
Making njs_value_property_i64() and njs_value_property_i64_set() fast.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 12 Jan 2022 17:58:19 +0000 (17:58 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 12 Jan 2022 17:58:19 +0000 (17:58 +0000)
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.

src/njs_value.h

index 5dfb8e9da412acf0c6df6d9166af530f8561ece6..12448eacd3a6bd5b8106cd65067d6fa0035a685e 100644 (file)
@@ -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);
 }