summaryrefslogtreecommitdiff
path: root/match.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-09-06 18:04:10 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-09-06 18:58:08 -0700
commit5fdec18edca87d2fd0ae6b58104d9029a75275f0 (patch)
treee8a6eecc42ae70eb4117ea8afe5e940797adbf0c /match.c
parentec97545637a6310367ce9a3bdf2b3206e0b85d3b (diff)
Avoid unnecessary matrix access
Diffstat (limited to 'match.c')
-rw-r--r--match.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/match.c b/match.c
index 1bc7998..25e08c8 100644
--- a/match.c
+++ b/match.c
@@ -110,6 +110,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;
for(int j = 0; j < m; j++){
score_t score = SCORE_MIN;
if(tolower(needle[i]) == tolower(haystack[j])){
@@ -125,12 +126,13 @@ 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, M[i][j-1] + SCORE_GAP_TRAILING);
+ score = max(score, prev_score + SCORE_GAP_TRAILING);
}else{
- score = max(score, M[i][j-1] + SCORE_GAP_INNER);
+ score = max(score, prev_score + SCORE_GAP_INNER);
}
}
M[i][j] = score;
+ prev_score = score;
}
}