mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
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. :^)
This commit is contained in:
parent
d640031214
commit
801f74362e
1 changed files with 6 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue