]> git.kaiwu.me - njs.git/commitdiff
String.indexOf() and String.includes() simplification.
authorValentin Bartenev <vbart@nginx.com>
Wed, 9 Nov 2016 11:34:32 +0000 (14:34 +0300)
committerValentin Bartenev <vbart@nginx.com>
Wed, 9 Nov 2016 11:34:32 +0000 (14:34 +0300)
njs/njs_string.c

index 2931168191b1769072f9a0fbc20f493010c27dd9..9ca720241e8eac3c6c1189145d48e22f865034ea 100644 (file)
@@ -1220,10 +1220,6 @@ njs_string_prototype_index_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         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 *vm, njs_value_t *args, nxt_uint_t nargs,
             }
         }
 
-        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 *vm, njs_value_t *args, nxt_uint_t nargs,
         }
     }
 
-small:
-
     index = -1;
 
 done:
@@ -1393,10 +1387,6 @@ njs_string_prototype_includes(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
         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 *vm, njs_value_t *args, nxt_uint_t nargs,
             }
         }
 
-        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 *vm, njs_value_t *args, nxt_uint_t nargs,
         }
     }
 
-small:
-
     retval = &njs_value_false;
 
 done: