fzy

terminal fuzzy finder picker

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

commit dbf0874b323935c304ff838b2e900607d044a795
parent 73187cac1fc962d582f5dffe42d48936bffd70f3
Author: John Hawthorn <john.hawthorn@gmail.com>
Date:   Tue,  7 Jun 2016 23:28:31 -0700

Move equality detection within calculate_score

Diffstat:
Msrc/match.c | 26+++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/match.c b/src/match.c @@ -56,12 +56,23 @@ void mat_print(score_t *mat, char name, const char *needle, const char *haystack #endif score_t calculate_score(const char *needle, const char *haystack, size_t *positions) { - if (!*haystack || !*needle) + if (!*needle) return SCORE_MIN; int n = strlen(needle); int m = strlen(haystack); + if (n == m) { + /* Since this method can only be called with a haystack which + * matches needle. If the lengths of the strings are equal the + * strings themselves must also be equal (ignoring case). + */ + if (positions) + for (int i = 0; i < n; i++) + positions[i] = i; + return SCORE_MAX; + } + if (m > 1024) { /* * Unreasonably large candidate: return no score @@ -164,18 +175,7 @@ score_t calculate_score(const char *needle, const char *haystack, size_t *positi } score_t match_positions(const char *needle, const char *haystack, size_t *positions) { - if (!*needle) { - return SCORE_MAX; - } else if (!strcasecmp(needle, haystack)) { - if (positions) { - int n = strlen(needle); - for (int i = 0; i < n; i++) - positions[i] = i; - } - return SCORE_MAX; - } else { - return calculate_score(needle, haystack, positions); - } + return calculate_score(needle, haystack, positions); } score_t match(const char *needle, const char *haystack) {