From c25561c6508b3aaf8bee8e3860fd8c22de37eb00 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 8 Apr 2024 10:10:56 -0700 Subject: [PATCH] Cache value before entering spacer macro --- src/modal.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modal.c b/src/modal.c index 0f543c4..d7a2880 100644 --- a/src/modal.c +++ b/src/modal.c @@ -25,7 +25,7 @@ walk(char *s) if(!depth) return s; } } - while(!spacer(s[0]) && *s++) + while((c = *s) && !spacer(c) && *s++) ; return s; } @@ -63,7 +63,8 @@ match(char *p, Rule *r) if(*a != *b) return NULL; a++, b++; } - return spacer(*b) ? b : NULL; + c = *b; + return spacer(c) ? b : NULL; } static char * @@ -81,8 +82,8 @@ plode(char *s) } else { /* explode */ *outp_++ = *s++, *outp_++ = ' '; while((c = *s++) && !spacer(c)) { - *outp_++ = '(', *outp_++ = c, depth++; - if(!spacer(*s)) + *outp_++ = '(', *outp_++ = c, depth++, c = *s; + if(!spacer(c)) *outp_++ = ' '; } for(i = 0; i < depth; i++) @@ -135,7 +136,7 @@ parse_rule(char *s) static int rewrite(void) { - char c, last = 0, *p = direction ? bank_b : bank_a, *o = p; + char c, c_ = 0, last = 0, *p = direction ? bank_b : bank_a, *o = p; while((c = *p) && c <= ' ') p++; while((c = *p)) { int i; @@ -148,7 +149,8 @@ rewrite(void) r->b = parse_rule(p), p = walk(p); return save(-1, p); } - if(p == o || spacer(*(p - 1))) { + if(p != o) c_ = *(p - 1); + if(p == o || spacer(c_)) { for(i = 0; i < rules_len; i++) { Rule *r = &rules[i]; char *res = match(p, r);