From c80b65b8276dd3f2edc21ec0e3e304b45522e24b Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 3 Oct 2021 02:22:05 +0330 Subject: [PATCH] LibRegex: Avoid creating a new temporary RegexStringView in Char compare Instead of making a new string to compare against, simply grab the first code unit of the input and compare against that. --- Userland/Libraries/LibRegex/RegexByteCode.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp index 2b6bc146c7..9f979d75f7 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.cpp +++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp @@ -555,15 +555,12 @@ ALWAYS_INLINE void OpCode_Compare::compare_char(MatchInput const& input, MatchSt if (state.string_position == input.view.length()) return; - auto input_view = input.view.substring_view(state.string_position, 1); - Optional str; - Vector utf16; - auto compare_view = input_view.construct_as_same({ &ch1, 1 }, str, utf16); + auto input_view = input.view.substring_view(state.string_position, 1)[0]; bool equal; if (input.regex_options & AllFlags::Insensitive) - equal = input_view.equals_ignoring_case(compare_view); + equal = to_ascii_lowercase(input_view) == to_ascii_lowercase(ch1); // FIXME: Implement case-insensitive matching for non-ascii characters else - equal = input_view.equals(compare_view); + equal = input_view == ch1; if (equal) { if (inverse)