Welcome! Log In Create A New Profile

Advanced

[njs] Improved njs_value_property_i64_delete() for fast-arrays.

Dmitry Volyntsev
November 10, 2022 08:56PM
details: https://hg.nginx.org/njs/rev/5964ac864676
branches:
changeset: 1995:5964ac864676
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Nov 10 17:53:35 2022 -0800
description:
Improved njs_value_property_i64_delete() for fast-arrays.

diffstat:

src/njs_value.c | 33 +++++++++++++++++++++++++++------
src/njs_value.h | 6 +-----
src/njs_vmcode.c | 14 ++++++++++++++
3 files changed, 42 insertions(+), 11 deletions(-)

diffs (93 lines):

diff -r ecf6c3e56857 -r 5964ac864676 src/njs_value.c
--- a/src/njs_value.c Thu Nov 10 17:51:32 2022 -0800
+++ b/src/njs_value.c Thu Nov 10 17:53:35 2022 -0800
@@ -1329,20 +1329,41 @@ njs_int_t
njs_value_property_delete(njs_vm_t *vm, njs_value_t *value, njs_value_t *key,
njs_value_t *removed, njs_bool_t thrw)
{
+ double num;
+ uint32_t index;
njs_int_t ret;
- njs_value_t primitive;
+ njs_array_t *array;
njs_object_prop_t *prop;
njs_property_query_t pq;

- if (njs_slow_path(!njs_is_key(key))) {
- ret = njs_value_to_key(vm, &primitive, key);
- if (njs_slow_path(ret != NJS_OK)) {
- return NJS_ERROR;
+ njs_assert(njs_is_index_or_key(key));
+
+ if (njs_fast_path(njs_is_number(key))) {
+ if (njs_slow_path(!(njs_is_fast_array(value)))) {
+ goto slow_path;
+ }
+
+ num = njs_number(key);
+
+ if (njs_slow_path(!njs_number_is_integer_index(num))) {
+ goto slow_path;
}

- key = &primitive;
+ index = (uint32_t) num;
+
+ array = njs_array(value);
+
+ if (njs_slow_path(index >= array->length)) {
+ goto slow_path;
+ }
+
+ njs_value_assign(&array->start[index], &njs_value_invalid);
+
+ return NJS_OK;
}

+slow_path:
+
njs_property_query_init(&pq, NJS_PROPERTY_QUERY_DELETE, 0, 1);

ret = njs_property_query(vm, &pq, value, key);
diff -r ecf6c3e56857 -r 5964ac864676 src/njs_value.h
--- a/src/njs_value.h Thu Nov 10 17:51:32 2022 -0800
+++ b/src/njs_value.h Thu Nov 10 17:53:35 2022 -0800
@@ -1142,13 +1142,9 @@ njs_inline njs_int_t
njs_value_property_i64_delete(njs_vm_t *vm, njs_value_t *value, int64_t index,
njs_value_t *removed)
{
- 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_delete(vm, value, &key, removed, 1);
}
diff -r ecf6c3e56857 -r 5964ac864676 src/njs_vmcode.c
--- a/src/njs_vmcode.c Thu Nov 10 17:51:32 2022 -0800
+++ b/src/njs_vmcode.c Thu Nov 10 17:53:35 2022 -0800
@@ -932,6 +932,20 @@ NEXT_LBL;
njs_vmcode_operand(vm, vmcode->operand3, value2);
njs_vmcode_operand(vm, vmcode->operand2, value1);

+ if (njs_slow_path(!njs_is_index_or_key(value2))) {
+ if (njs_slow_path(njs_is_null_or_undefined(value1))) {
+ (void) njs_throw_cannot_property(vm, value1, value2, "delete");
+ goto error;
+ }
+
+ ret = njs_value_to_key(vm, &primitive1, value2);
+ if (njs_slow_path(ret != NJS_OK)) {
+ goto error;
+ }
+
+ value2 = &primitive1;
+ }
+
ret = njs_value_property_delete(vm, value1, value2, NULL, 1);
if (njs_fast_path(ret != NJS_ERROR)) {
vm->retval = njs_value_true;
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Improved njs_value_property_i64_delete() for fast-arrays.

Dmitry Volyntsev 197 November 10, 2022 08:56PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 84
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready