From 9d16ab4997ce6eb211ff3fdf06275d3f6bf5ebdc Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 10 Jul 2016 12:42:06 -0700 Subject: Use standards-compliant lookup table --- src/match.c | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'src/match.c') 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 #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; } } -- cgit v1.2.3