diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-06 18:04:10 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-06 18:58:08 -0700 |
commit | 5fdec18edca87d2fd0ae6b58104d9029a75275f0 (patch) | |
tree | e8a6eecc42ae70eb4117ea8afe5e940797adbf0c /match.c | |
parent | ec97545637a6310367ce9a3bdf2b3206e0b85d3b (diff) |
Avoid unnecessary matrix access
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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; } } |