aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-11-26 07:06:08 -0500
committerB. Watson <urchlay@slackware.uk>2025-11-26 07:06:08 -0500
commit10865a35bc9cce9a24ed3fed120ba4d57cb5e963 (patch)
tree1e6b6c3ed0591f55cb31dd7cf98f73cb8e14d655
parent829fd938876f1bbad56bfa792ab8a0a0a18b8fc6 (diff)
downloadunalf-10865a35bc9cce9a24ed3fed120ba4d57cb5e963.tar.gz
Search backwards for tokens, ~30% speedup. Still slow.
-rw-r--r--src/alf.c19
1 files 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) {