Browse code

Rearrance calculate_score inner loop for clarity

John Hawthorn authored on 07/09/2014 00:29:06
Showing 1 changed files

  • match.c index 0c50eb7..1bc7998 100644
... ...
@@ -112,19 +112,17 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio
112 112
 	for(int i = 0; i < n; i++){
113 113
 		for(int j = 0; j < m; j++){
114 114
 			score_t score = SCORE_MIN;
115
-			int match = tolower(needle[i]) == tolower(haystack[j]);
116
-			D[i][j] = SCORE_MIN;
117
-			if(match){
118
-				if(i && j){
115
+			if(tolower(needle[i]) == tolower(haystack[j])){
116
+				if(!i){
117
+					score = (j * SCORE_GAP_LEADING) + match_bonus[j];
118
+				}else if(j){
119 119
 					score = max(score, M[i-1][j-1] + match_bonus[j]);
120 120
 
121 121
 					/* consecutive match, doesn't stack with match_bonus */
122 122
 					score = max(score, D[i-1][j-1] + SCORE_MATCH_CONSECUTIVE);
123
-				}else if(!i){
124
-					score = (j * SCORE_GAP_LEADING) + match_bonus[j];
125 123
 				}
126
-				D[i][j] = score;
127 124
 			}
125
+			D[i][j] = score;
128 126
 			if(j){
129 127
 				if(i == n-1){
130 128
 					score = max(score, M[i][j-1] + SCORE_GAP_TRAILING);