summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2016-06-13 23:55:58 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2016-06-22 18:32:15 -0700
commita9b4925cf02c6be7064916b07d0031df7c4d5b5a (patch)
tree321bb2ced29313209fb090435681e88d7f05fa18 /src
parent6d352b39cb8edca87705065a5b87e6208cafba6b (diff)
Change match into if/else
This is marginally faster and I still think it reads very well (maybe better).
Diffstat (limited to 'src')
-rw-r--r--src/match.c10
1 files changed, 7 insertions, 3 deletions
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);
}
}