From 10865a35bc9cce9a24ed3fed120ba4d57cb5e963 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 26 Nov 2025 07:06:08 -0500 Subject: Search backwards for tokens, ~30% speedup. Still slow. --- src/alf.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/alf.c b/src/alf.c index 27b6d86..7b27861 100644 --- a/src/alf.c +++ b/src/alf.c @@ -200,22 +200,19 @@ void store_token(int tok) { } } +/* search backwards, the tokens are stored with longer ones later + in the list. */ int match_token(int pos) { - int i, bestmatch = -1; + int i; - for(i = 0; i < curr_token; i++) { - if(i == TOK_RESET || i == TOK_END) - continue; + for(i = curr_token - 1; i >= INIT_TOKEN; i--) { if(memcmp(&input_buf[pos], tokentab[i].start, tokentab[i].length) == 0) - bestmatch = i; - } - - if(bestmatch == -1) { - fprintf(stderr, "BUG: bestmatch is -1, this should never happen!\n"); - exit(1); + return i; } - return bestmatch; + /* hard-coded single character tokens map to their values, no need + to search. */ + return input_buf[pos]; } void make_token(int start, int end) { -- cgit v1.2.3