mirror of
https://github.com/neovim/neovim
synced 2025-07-17 09:41:46 +00:00
fix(search): avoid quadratic time complexity when computing fuzzy score (#32153)
(cherry picked from commit a8b6fa07c4
)
This commit is contained in:
committed by
github-actions[bot]
parent
46cc8a52b2
commit
f132efaefb
@ -2964,6 +2964,8 @@ static int fuzzy_match_compute_score(const char *const str, const int strSz,
|
|||||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
||||||
{
|
{
|
||||||
assert(numMatches > 0); // suppress clang "result of operation is garbage"
|
assert(numMatches > 0); // suppress clang "result of operation is garbage"
|
||||||
|
const char *p = str;
|
||||||
|
uint32_t sidx = 0;
|
||||||
// Initialize score
|
// Initialize score
|
||||||
int score = 100;
|
int score = 100;
|
||||||
|
|
||||||
@ -2996,12 +2998,12 @@ static int fuzzy_match_compute_score(const char *const str, const int strSz,
|
|||||||
// Check for bonuses based on neighbor character value
|
// Check for bonuses based on neighbor character value
|
||||||
if (currIdx > 0) {
|
if (currIdx > 0) {
|
||||||
// Camel case
|
// Camel case
|
||||||
const char *p = str;
|
|
||||||
int neighbor = ' ';
|
int neighbor = ' ';
|
||||||
|
|
||||||
for (uint32_t sidx = 0; sidx < currIdx; sidx++) {
|
while (sidx < currIdx) {
|
||||||
neighbor = utf_ptr2char(p);
|
neighbor = utf_ptr2char(p);
|
||||||
MB_PTR_ADV(p);
|
MB_PTR_ADV(p);
|
||||||
|
sidx++;
|
||||||
}
|
}
|
||||||
const int curr = utf_ptr2char(p);
|
const int curr = utf_ptr2char(p);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user