From 214410b3979ceef274fc525dad628d27615edaf8 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sun, 13 Jun 2021 22:30:02 +0200 Subject: [PATCH] LibRegex: Avoid making unnecessary string copies --- Userland/Libraries/LibRegex/RegexByteCode.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp index feb20cf743..2f51ddd8b0 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.cpp +++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp @@ -528,15 +528,13 @@ ALWAYS_INLINE bool OpCode_Compare::compare_string(const MatchInput& input, Match auto str_view1 = StringView(str, length); auto str_view2 = StringView(&input.view.u8view()[state.string_position], length); - String str1, str2; - if (input.regex_options & AllFlags::Insensitive) { - str1 = str_view1.to_string().to_lowercase(); - str2 = str_view2.to_string().to_lowercase(); - str_view1 = str1.view(); - str_view2 = str2.view(); - } + bool string_equals; + if (input.regex_options & AllFlags::Insensitive) + string_equals = str_view1.equals_ignoring_case(str_view2); + else + string_equals = str_view1 == str_view2; - if (str_view1 == str_view2) { + if (string_equals) { state.string_position += length; if (length == 0) had_zero_length_match = true;