From bacbc376a0ee19f9d9f8ecf91efc1b3054bdef11 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 29 Dec 2023 17:22:27 +0100 Subject: [PATCH] AK: Make StringView::contains(StringView) faster for 1-byte needles If we're looking for a 1-byte string, we can do the much simpler byte scan by simply forwarding the call to StringView::contains(char). --- AK/StringView.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AK/StringView.cpp b/AK/StringView.cpp index 6150943bf9..e9e8c7f90f 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -167,6 +167,8 @@ bool StringView::contains(u32 needle) const bool StringView::contains(StringView needle, CaseSensitivity case_sensitivity) const { + if (needle.length() == 1) + return contains(needle.characters_without_null_termination()[0]); return StringUtils::contains(*this, needle, case_sensitivity); }