From 9de25c06435f952ef2b96a0babca5b5fc925dab1 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 9 Nov 2016 14:34:32 +0300 Subject: [PATCH] String.indexOf() and String.includes() simplification. --- njs/njs_string.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/njs/njs_string.c b/njs/njs_string.c index 29311681..9ca72024 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -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: -- 2.47.3