mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:17:35 +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 "FuzzyMatch.h"
|
||||||
|
#include <AK/CharacterTypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace Assistant {
|
namespace Assistant {
|
||||||
|
@ -41,7 +42,7 @@ static FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const
|
||||||
bool first_match = true;
|
bool first_match = true;
|
||||||
while (needle_idx < needle.length() && haystack_idx < haystack.length()) {
|
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)
|
if (next_match >= MAX_MATCHES)
|
||||||
return { false, out_score };
|
return { false, out_score };
|
||||||
|
|
||||||
|
@ -87,13 +88,13 @@ static FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_idx > 0) {
|
if (current_idx > 0) {
|
||||||
auto current_character = haystack.substring(current_idx, 1);
|
u32 current_character = haystack[current_idx];
|
||||||
auto neighbor_character = haystack.substring(current_idx - 1, 1);
|
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;
|
out_score += CAMEL_BONUS;
|
||||||
|
|
||||||
if (neighbor_character == "_" || neighbor_character == " ")
|
if (neighbor_character == '_' || neighbor_character == ' ')
|
||||||
out_score += SEPARATOR_BONUS;
|
out_score += SEPARATOR_BONUS;
|
||||||
} else {
|
} else {
|
||||||
out_score += FIRST_LETTER_BONUS;
|
out_score += FIRST_LETTER_BONUS;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue