From 8df2a496cc932ab7ef9bbbb9af02e98c3b49a2e6 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Tue, 16 Apr 2024 13:51:34 -0700 Subject: [PATCH] Reduce register clearing tasks --- src/modal.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modal.c b/src/modal.c index fd54d02..e159e28 100644 --- a/src/modal.c +++ b/src/modal.c @@ -5,7 +5,7 @@ typedef struct { char *a, *b; } Rule; -static int flip, cycles = 0x10000; +static int flip, rmin = 0xff, rmax = 0x00, cycles = 0x10000; static Rule rules[0x1000], lambda, *rules_ = rules; static char dict[0x8000], *dict_ = dict; static char bank_a[0x4000], *src_ = bank_a; @@ -37,8 +37,11 @@ set_reg(int r, char *b) char *a = regs[r], *aa = walk(a), *bb = walk(b); while(a < aa && b < bb) if(*a++ != *b++) return 0; - } else + } else { regs[r] = b; + if(r < rmin) rmin = r; + if(r > rmax) rmax = r; + } return 1; } @@ -87,8 +90,11 @@ match_rule(Rule *r, char *p) { int i; char c, last = 0, *a = r->a, *b = p; - for(i = 0x21; i < 0x7f; i++) - regs[i] = 0; + if(rmax) { + for(i = 0; i <= rmax; i++) + regs[i] = 0; + rmin = 0xff, rmax = 0x00; + } while((c = *a)) { if(spacer(last) && c == '?') { if(!set_reg(*(++a), b)) return NULL;