summaryrefslogtreecommitdiff
path: root/src/match.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2016-07-10 12:42:06 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2016-07-12 00:42:48 -0700
commit9d16ab4997ce6eb211ff3fdf06275d3f6bf5ebdc (patch)
tree8a011e6a9c6afe04fd6aa5f3ce2f8a7de9a0bdfc /src/match.c
parente6cb871f4fe58c09c9aca29d6402fc7369caf759 (diff)
Use standards-compliant lookup table
Diffstat (limited to 'src/match.c')
-rw-r--r--src/match.c28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/match.c b/src/match.c
index 6e1489f..3fa24b8 100644
--- a/src/match.c
+++ b/src/match.c
@@ -6,6 +6,7 @@
#include <math.h>
#include "match.h"
+#include "bonus.h"
#include "../config.h"
@@ -55,38 +56,13 @@ void mat_print(score_t *mat, char name, const char *needle, const char *haystack
}
#endif
-const score_t bonus_states[][256] = {
- { 0 },
- {
- ['/'] = SCORE_MATCH_SLASH,
- ['-'] = SCORE_MATCH_WORD,
- ['_'] = SCORE_MATCH_WORD,
- [' '] = SCORE_MATCH_WORD,
- ['.'] = SCORE_MATCH_DOT,
- },
- {
- ['a' ... 'z'] = SCORE_MATCH_CAPITAL,
- ['/'] = SCORE_MATCH_SLASH,
- ['-'] = SCORE_MATCH_WORD,
- ['_'] = SCORE_MATCH_WORD,
- [' '] = SCORE_MATCH_WORD,
- ['.'] = SCORE_MATCH_DOT,
- },
-};
-
-const size_t bonus_index[256] = {
- ['A' ... 'Z'] = 2,
- ['a' ... 'z'] = 1,
- ['0' ... '9'] = 1,
-};
-
static void precompute_bonus(const char *haystack, score_t *match_bonus) {
/* Which positions are beginning of words */
int m = strlen(haystack);
char last_ch = '/';
for (int i = 0; i < m; i++) {
char ch = haystack[i];
- match_bonus[i] = bonus_states[bonus_index[(size_t)ch]][(size_t)last_ch];
+ match_bonus[i] = COMPUTE_BONUS(last_ch, ch);
last_ch = ch;
}
}