fzy

terminal fuzzy finder picker

git clone https://9o.is/git/fzy.git

commit 0c1c6b65e3aaaf1ad458cf3fc9ad422ade967458
parent 2c0ad46e24c2b5c4cbc5af2d047fcbfa583b0d59
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Sat,  6 Sep 2014 18:07:01 -0700

Optimize inner loop

Diffstat:
Mmatch.c | 9++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/match.c b/match.c @@ -111,6 +111,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio for(int i = 0; i < n; i++){ double prev_score = SCORE_MIN; + double gap_score = i == n-1 ? SCORE_GAP_TRAILING : SCORE_GAP_INNER; for(int j = 0; j < m; j++){ score_t score = SCORE_MIN; if(tolower(needle[i]) == tolower(haystack[j])){ @@ -124,13 +125,7 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio } } D[i][j] = score; - if(j){ - if(i == n-1){ - score = max(score, prev_score + SCORE_GAP_TRAILING); - }else{ - score = max(score, prev_score + SCORE_GAP_INNER); - } - } + score = max(score, prev_score + gap_score); M[i][j] = score; prev_score = score; }