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

Valentin Bartenev vbart at nginx.com
Wed Nov 9 11:34:59 UTC 2016


details:   http://hg.nginx.org/njs/rev/c8862eb2eb94
branches:  
changeset: 244:c8862eb2eb94
user:      Valentin Bartenev <vbart at 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:



More information about the nginx-devel mailing list