Przeglądaj źródła

Assistant: Use StringView more in FileProvider fuzzy matching code

By not allocating new String objects, the fuzzy matcher becomes a lot
faster and more responsive while typing. :^)
Andreas Kling 4 lat temu
rodzic
commit
801f74362e
1 zmienionych plików z 6 dodań i 5 usunięć
  1. 6 5
      Userland/Applications/Assistant/FuzzyMatch.cpp

+ 6 - 5
Userland/Applications/Assistant/FuzzyMatch.cpp

@@ -5,6 +5,7 @@
  */
 
 #include "FuzzyMatch.h"
+#include <AK/CharacterTypes.h>
 #include <string.h>
 
 namespace Assistant {
@@ -41,7 +42,7 @@ static FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const
     bool first_match = true;
     while (needle_idx < needle.length() && haystack_idx < haystack.length()) {
 
-        if (needle.substring(needle_idx, 1).to_lowercase() == haystack.substring(haystack_idx, 1).to_lowercase()) {
+        if (needle.substring_view(needle_idx, 1).equals_ignoring_case(haystack.substring_view(haystack_idx, 1))) {
             if (next_match >= MAX_MATCHES)
                 return { false, out_score };
 
@@ -87,13 +88,13 @@ static FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const
             }
 
             if (current_idx > 0) {
-                auto current_character = haystack.substring(current_idx, 1);
-                auto neighbor_character = haystack.substring(current_idx - 1, 1);
+                u32 current_character = haystack[current_idx];
+                u32 neighbor_character = haystack[current_idx - 1];
 
-                if (neighbor_character != neighbor_character.to_uppercase() && current_character != current_character.to_lowercase())
+                if (neighbor_character != to_ascii_uppercase(neighbor_character) && current_character != to_ascii_lowercase(current_character))
                     out_score += CAMEL_BONUS;
 
-                if (neighbor_character == "_" || neighbor_character == " ")
+                if (neighbor_character == '_' || neighbor_character == ' ')
                     out_score += SEPARATOR_BONUS;
             } else {
                 out_score += FIRST_LETTER_BONUS;