mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Do not require an allocated String for fuzzy matching
A StringView is sufficient here. This also removes the declaration of fuzzy_match_recursive from the header, as it's only needed from within the implementation file.
This commit is contained in:
parent
d4acdac317
commit
11bd6c3d68
Notes:
sideshowbarker
2024-07-17 07:35:03 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/11bd6c3d68 Pull-request: https://github.com/SerenityOS/serenity/pull/15280
2 changed files with 5 additions and 8 deletions
|
@ -21,7 +21,7 @@ static constexpr int const LEADING_LETTER_PENALTY = -5; // penalty applied
|
|||
static constexpr int const MAX_LEADING_LETTER_PENALTY = -15; // maximum penalty for leading letters
|
||||
static constexpr int const UNMATCHED_LETTER_PENALTY = -1; // penalty for every letter that doesn't matter
|
||||
|
||||
static int calculate_score(String const& string, u8* index_points, size_t index_points_size)
|
||||
static int calculate_score(StringView string, u8* index_points, size_t index_points_size)
|
||||
{
|
||||
int out_score = 100;
|
||||
|
||||
|
@ -59,7 +59,7 @@ static int calculate_score(String const& string, u8* index_points, size_t index_
|
|||
return out_score;
|
||||
}
|
||||
|
||||
FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const& haystack, size_t needle_idx, size_t haystack_idx,
|
||||
static FuzzyMatchResult fuzzy_match_recursive(StringView needle, StringView haystack, size_t needle_idx, size_t haystack_idx,
|
||||
u8 const* src_matches, u8* matches, int next_match, int& recursion_count)
|
||||
{
|
||||
int out_score = 0;
|
||||
|
@ -125,7 +125,7 @@ FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const& hayst
|
|||
// Scores are not normalized between any values and have no particular meaning. The starting value is 100 and when we
|
||||
// detect good indicators of a match we add to the score. When we detect bad indicators, we penalize the match and subtract
|
||||
// from its score. Therefore, the longer the needle/haystack the greater the range of scores could be.
|
||||
FuzzyMatchResult fuzzy_match(String const& needle, String const& haystack)
|
||||
FuzzyMatchResult fuzzy_match(StringView needle, StringView haystack)
|
||||
{
|
||||
int recursion_count = 0;
|
||||
u8 matches[MAX_MATCHES] {};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -15,10 +15,7 @@ struct FuzzyMatchResult {
|
|||
int score { 0 };
|
||||
};
|
||||
|
||||
FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const& haystack, size_t needle_idx, size_t haystack_idx,
|
||||
u8 const* src_matches, u8* matches, int next_match, int& recursion_count);
|
||||
|
||||
FuzzyMatchResult fuzzy_match(String const& needle, String const& haystack);
|
||||
FuzzyMatchResult fuzzy_match(StringView needle, StringView haystack);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue