Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2017-11-09 15:26:47 +0300
committerBen Noordhuis <info@bnoordhuis.nl>2017-11-15 14:01:20 +0300
commit0fdd88a374e23e1dd4a05d93afd5eb0c3b080fd5 (patch)
treed49aa6b60bddaa61e39b613f888acb196269c375 /src/string_search.h
parentfdbb6dd042a560fc5d3b3ad682a13ddf506128e6 (diff)
module: speed up package.json parsing more
Move the logic from the previous commit to C++ land in order to avoid creating a new string when we know we won't parse it anyway. PR-URL: https://github.com/nodejs/node/pull/15767 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/string_search.h')
-rw-r--r--src/string_search.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/string_search.h b/src/string_search.h
index 6e76a5b8f41..51f72062a99 100644
--- a/src/string_search.h
+++ b/src/string_search.h
@@ -638,6 +638,7 @@ size_t SearchString(const Char* haystack,
size_t needle_length,
size_t start_index,
bool is_forward) {
+ if (haystack_length < needle_length) return haystack_length;
// To do a reverse search (lastIndexOf instead of indexOf) without redundant
// code, create two vectors that are reversed views into the input strings.
// For example, v_needle[0] would return the *last* character of the needle.
@@ -646,7 +647,6 @@ size_t SearchString(const Char* haystack,
needle, needle_length, is_forward);
Vector<const Char> v_haystack = Vector<const Char>(
haystack, haystack_length, is_forward);
- CHECK(haystack_length >= needle_length);
size_t diff = haystack_length - needle_length;
size_t relative_start_index;
if (is_forward) {
@@ -664,6 +664,15 @@ size_t SearchString(const Char* haystack,
}
return is_forward ? pos : (haystack_length - needle_length - pos);
}
+
+template <size_t N>
+size_t SearchString(const char* haystack, size_t haystack_length,
+ const char (&needle)[N]) {
+ return SearchString(
+ reinterpret_cast<const uint8_t*>(haystack), haystack_length,
+ reinterpret_cast<const uint8_t*>(needle), N - 1, 0, true);
+}
+
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS