Faster rewrite

This commit is contained in:
Devine Lu Linvega 2024-04-08 10:32:06 -07:00
parent 09e9e45338
commit 6e60bebf3d
1 changed files with 5 additions and 5 deletions

View File

@ -11,7 +11,7 @@ static char bank_a[0x4000], *prog_ = bank_a;
static char bank_b[0x4000], *outp_ = bank_b; static char bank_b[0x4000], *outp_ = bank_b;
static char *regs[0x100]; static char *regs[0x100];
#define spacer(c) (c < 0x21 || c == '(' || c == ')') #define spacer(c) (c < 0x21 || c == '(' || c == ')' || !c)
static char * static char *
walk(char *s) walk(char *s)
@ -149,13 +149,13 @@ add_rule(char *p)
static int static int
rewrite(void) rewrite(void)
{ {
char c, c_ = 0, last = 0, *p = direction ? bank_b : bank_a, *o = p; char c, last = 0, *p = direction ? bank_b : bank_a;
while((c = *p) && c <= ' ') p++; while((c = *p) && c <= ' ') p++;
while((c = *p)) { while((c = *p)) {
int i; int i;
if(p[0] == '<' && p[1] == '>') return add_rule(p); if(p[0] == '<' && p[1] == '>')
if(p != o) c_ = *(p - 1); return add_rule(p);
if(p == o || spacer(c_)) { if(spacer(last)) {
for(i = 0; i < rules_len; i++) { for(i = 0; i < rules_len; i++) {
Rule *r = &rules[i]; Rule *r = &rules[i];
char *res = match_rule(p, r); char *res = match_rule(p, r);