From fbab9bc3305e7a7418e8eb5689b456607cfbb6bd Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 14 Jul 2023 12:29:30 +0330 Subject: [PATCH] LibRegex: Avoid pointlessly slicing a UTF-16 string for one code unit This simple change is a nice 9% speedup on the regex test suite :^) --- Userland/Libraries/LibRegex/RegexByteCode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp index 80972d8f6d..7532d67132 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.cpp +++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp @@ -559,7 +559,7 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M auto range_data = m_bytecode->template spans<4>().slice(offset, count); offset += count; - auto ch = input.view.substring_view(state.string_position, 1)[0]; + auto ch = input.view[state.string_position_in_code_units]; auto const* matching_range = binary_search(range_data, ch, nullptr, [insensitive = input.regex_options & AllFlags::Insensitive](auto needle, CharRange range) { auto upper_case_needle = needle;