diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-03 17:56:12 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-03 20:03:53 +0200 |
commit | 801f74362ee7e11b3f561c362d47571663c580fc (patch) | |
tree | 95ea384cfd106e63abdbcb003b2210f680a3e98e | |
parent | d64003121413c37029e14f497f3828555fc4138b (diff) | |
download | serenity-801f74362ee7e11b3f561c362d47571663c580fc.zip |
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. :^)
-rw-r--r-- | Userland/Applications/Assistant/FuzzyMatch.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Userland/Applications/Assistant/FuzzyMatch.cpp b/Userland/Applications/Assistant/FuzzyMatch.cpp index e6c2814cb4..a01e039386 100644 --- a/Userland/Applications/Assistant/FuzzyMatch.cpp +++ b/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; |