Welcome! Log In Create A New Profile

Advanced

[njs] String.indexOf() and String.includes() simplification.

Valentin Bartenev
November 09, 2016 06:36AM
details: http://hg.nginx.org/njs/rev/c8862eb2eb94
branches:
changeset: 244:c8862eb2eb94
user: Valentin Bartenev <vbart@nginx.com>
date: Wed Nov 09 14:34:32 2016 +0300
description:
String.indexOf() and String.includes() simplification.

diffstat:

njs/njs_string.c | 16 ++--------------
1 files changed, 2 insertions(+), 14 deletions(-)

diffs (61 lines):

diff -r 8e800470d756 -r c8862eb2eb94 njs/njs_string.c
--- a/njs/njs_string.c Tue Nov 08 22:09:40 2016 +0300
+++ b/njs/njs_string.c Wed Nov 09 14:34:32 2016 +0300
@@ -1220,10 +1220,6 @@ njs_string_prototype_index_of(njs_vm_t *
length = njs_string_prop(&string, &args[0]);
search_length = njs_string_prop(&search, &args[1]);

- if (length < search_length) {
- goto small;
- }
-
index = 0;

if (nargs > 2) {
@@ -1234,7 +1230,7 @@ njs_string_prototype_index_of(njs_vm_t *
}
}

- if (index < length) {
+ if (length - index >= search_length) {
end = string.start + string.size;

if (string.size == (size_t) length) {
@@ -1272,8 +1268,6 @@ njs_string_prototype_index_of(njs_vm_t *
}
}

-small:
-
index = -1;

done:
@@ -1393,10 +1387,6 @@ njs_string_prototype_includes(njs_vm_t *

length = njs_string_prop(&string, &args[0]);

- if (length < search_length) {
- goto small;
- }
-
index = 0;

if (nargs > 2) {
@@ -1407,7 +1397,7 @@ njs_string_prototype_includes(njs_vm_t *
}
}

- if (index < length) {
+ if (length - index >= search_length) {
end = string.start + string.size;

if (string.size == (size_t) length) {
@@ -1431,8 +1421,6 @@ njs_string_prototype_includes(njs_vm_t *
}
}

-small:
-
retval = &njs_value_false;

done:

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] String.indexOf() and String.includes() simplification.

Valentin Bartenev 554 November 09, 2016 06:36AM



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

Online Users

Guests: 284
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready