Welcome! Log In Create A New Profile

Advanced

[njs] Simplified element access in Array.prototype.pop().

Dmitry Volyntsev
January 14, 2022 10:04AM
details: https://hg.nginx.org/njs/rev/762774041f05
branches:
changeset: 1805:762774041f05
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Jan 13 18:30:31 2022 +0000
description:
Simplified element access in Array.prototype.pop().

The change is similar to the previous commits.

diffstat:

src/njs_array.c | 60 +++++++++++++++++++-------------------------------------
1 files changed, 21 insertions(+), 39 deletions(-)

diffs (91 lines):

diff -r 2c1382bab643 -r 762774041f05 src/njs_array.c
--- a/src/njs_array.c Thu Jan 13 16:20:58 2022 +0000
+++ b/src/njs_array.c Thu Jan 13 18:30:31 2022 +0000
@@ -944,8 +944,7 @@ njs_array_prototype_pop(njs_vm_t *vm, nj
{
int64_t length;
njs_int_t ret;
- njs_array_t *array;
- njs_value_t *this, *entry;
+ njs_value_t *this;

this = njs_argument(args, 0);

@@ -954,40 +953,20 @@ njs_array_prototype_pop(njs_vm_t *vm, nj
return ret;
}

- njs_set_undefined(&vm->retval);
-
- if (njs_is_fast_array(this)) {
- array = njs_array(this);
-
- if (array->length != 0) {
- array->length--;
- entry = &array->start[array->length];
-
- if (njs_is_valid(entry)) {
- vm->retval = *entry;
-
- } else {
- /* src value may be in Array.prototype object. */
-
- ret = njs_value_property_i64(vm, this, array->length,
- &vm->retval);
- if (njs_slow_path(ret == NJS_ERROR)) {
- return NJS_ERROR;
- }
- }
- }
-
- return NJS_OK;
- }
-
ret = njs_object_length(vm, this, &length);
if (njs_slow_path(ret == NJS_ERROR)) {
return ret;
}

if (length == 0) {
+ ret = njs_object_length_set(vm, this, length);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
+
njs_set_undefined(&vm->retval);
- goto done;
+
+ return NJS_OK;
}

ret = njs_value_property_i64(vm, this, --length, &vm->retval);
@@ -995,16 +974,19 @@ njs_array_prototype_pop(njs_vm_t *vm, nj
return ret;
}

- ret = njs_value_property_i64_delete(vm, this, length, NULL);
- if (njs_slow_path(ret == NJS_ERROR)) {
- return ret;
- }
-
-done:
-
- ret = njs_object_length_set(vm, this, length);
- if (njs_slow_path(ret == NJS_ERROR)) {
- return ret;
+ if (njs_is_fast_array(this)) {
+ njs_array(this)->length--;
+
+ } else {
+ ret = njs_value_property_i64_delete(vm, this, length, NULL);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
+
+ ret = njs_object_length_set(vm, this, length);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ return ret;
+ }
}

return NJS_OK;
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Simplified element access in Array.prototype.pop().

Dmitry Volyntsev 71 January 14, 2022 10:04AM



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

Online Users

Guests: 68
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