From a9b4925cf02c6be7064916b07d0031df7c4d5b5a Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 13 Jun 2016 23:55:58 -0700 Subject: Change match into if/else This is marginally faster and I still think it reads very well (maybe better). --- src/match.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/match.c') diff --git a/src/match.c b/src/match.c index dac4b89..c2dc60a 100644 --- a/src/match.c +++ b/src/match.c @@ -117,9 +117,10 @@ score_t match_positions(const char *needle, const char *haystack, size_t *positi for (int i = 0; i < n; i++) { score_t prev_score = SCORE_MIN; score_t 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])) { + score_t score = SCORE_MIN; if (!i) { score = (j * SCORE_GAP_LEADING) + match_bonus[j]; } else if (j) { /* i > 0 && j > 0*/ @@ -129,9 +130,12 @@ score_t match_positions(const char *needle, const char *haystack, size_t *positi /* consecutive match, doesn't stack with match_bonus */ D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE); } + D[i][j] = score; + M[i][j] = prev_score = max(score, prev_score + gap_score); + } else { + D[i][j] = SCORE_MIN; + M[i][j] = prev_score = prev_score + gap_score; } - D[i][j] = score; - M[i][j] = prev_score = max(score, prev_score + gap_score); } } -- cgit v1.2.3