Browse Source

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.
Ali Mohammad Pur 3 years ago
parent
commit
c80b65b827
1 changed files with 3 additions and 6 deletions
  1. 3 6
      Userland/Libraries/LibRegex/RegexByteCode.cpp

+ 3 - 6
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())
     if (state.string_position == input.view.length())
         return;
         return;
 
 
-    auto input_view = input.view.substring_view(state.string_position, 1);
-    Optional<String> str;
-    Vector<u16, 1> 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;
     bool equal;
     if (input.regex_options & AllFlags::Insensitive)
     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
     else
-        equal = input_view.equals(compare_view);
+        equal = input_view == ch1;
 
 
     if (equal) {
     if (equal) {
         if (inverse)
         if (inverse)