aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-01-22 09:28:27 +0800
committerGitHub <noreply@github.com>2025-01-22 09:28:27 +0800
commita8b6fa07c4d9143f3bd279ce8fd87e8121da16e1 (patch)
treea8b1c78407c3cb91a366c916a8e2799f5fa38be9 /src
parent3a25995f304039517b99b8c7d79654adf65c7562 (diff)
downloadrneovim-a8b6fa07c4d9143f3bd279ce8fd87e8121da16e1.tar.gz
rneovim-a8b6fa07c4d9143f3bd279ce8fd87e8121da16e1.tar.bz2
rneovim-a8b6fa07c4d9143f3bd279ce8fd87e8121da16e1.zip
fix(search): avoid quadratic time complexity when computing fuzzy score (#32153)
Diffstat (limited to 'src')
-rw-r--r--src/nvim/search.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 5a53122739..6e87b07d06 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -2993,6 +2993,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
{
assert(numMatches > 0); // suppress clang "result of operation is garbage"
+ const char *p = str;
+ uint32_t sidx = 0;
// Initialize score
int score = 100;
bool is_exact_match = true;
@@ -3026,12 +3028,12 @@ static int fuzzy_match_compute_score(const char *const str, const int strSz,
// Check for bonuses based on neighbor character value
if (currIdx > 0) {
// Camel case
- const char *p = str;
int neighbor = ' ';
- for (uint32_t sidx = 0; sidx < currIdx; sidx++) {
+ while (sidx < currIdx) {
neighbor = utf_ptr2char(p);
MB_PTR_ADV(p);
+ sidx++;
}
const int curr = utf_ptr2char(p);