diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-09-18 13:44:23 -0400 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-09-20 11:08:54 +0100 |
commit | 11bd6c3d68f6fbe5ca538dc3d0b8224544bf3f9c (patch) | |
tree | 5651aa6aa7df33d440c0fa1aa02565361cb5bf26 /AK | |
parent | d4acdac3175da4edf0ca88c246a9e58307e3eefd (diff) | |
download | serenity-11bd6c3d68f6fbe5ca538dc3d0b8224544bf3f9c.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/FuzzyMatch.cpp | 6 | ||||
-rw-r--r-- | AK/FuzzyMatch.h | 7 |
2 files changed, 5 insertions, 8 deletions
diff --git a/AK/FuzzyMatch.cpp b/AK/FuzzyMatch.cpp index 3420e75e8e..8a1e313895 100644 --- a/AK/FuzzyMatch.cpp +++ b/AK/FuzzyMatch.cpp @@ -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] {}; diff --git a/AK/FuzzyMatch.h b/AK/FuzzyMatch.h index cc6a61fcf3..8480d6b636 100644 --- a/AK/FuzzyMatch.h +++ b/AK/FuzzyMatch.h @@ -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); } |