From 399ac8dd1734797013b5b232bf2c313761981f7d Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 24 Apr 2024 15:17:57 -0700 Subject: [PATCH] Do no allocate empty cells in dict --- src/modal.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/modal.c b/src/modal.c index 2e1fd8a..3944cc6 100644 --- a/src/modal.c +++ b/src/modal.c @@ -7,7 +7,7 @@ typedef struct { static int flip, quiet, cycles = 0x10000; static Rule rules[0x1000], *rules_ = rules, lambda; -static char dict[0x8000], *dict_ = dict; +static char dict[0x8000], *dict_ = dict, empty; static char bank_a[0x4000], *src_ = bank_a; static char bank_b[0x4000], *dst_ = bank_b; @@ -163,14 +163,11 @@ compile_rule(Rule *r, int id, char *src) { int wrapped, reg; char c, *cap; - r->id = id, r->ptr = 0; + r->id = id, r->ptr = 0, r->a = &empty, r->b = ∅ /* phase: left */ - r->a = r->b = dict_; while((c = *src) && c == ' ') src++; - if(c == ')' || (c == '<' && src[1] == '>')) { - *dict_++ = 0; - return src; - } + if(c == ')' || (c == '<' && src[1] == '>')) return src; + r->a = dict_; cap = walk(src); wrapped = c == '('; if(wrapped) src++, cap--; @@ -187,12 +184,9 @@ compile_rule(Rule *r, int id, char *src) src += wrapped; *dict_++ = 0; /* phase: right */ - r->b = dict_; while((c = *src) && c == ' ') src++; - if(c == ')' || (c == '<' && src[1] == '>')) { - *dict_++ = 0; - return src; - } + if(c == ')' || (c == '<' && src[1] == '>')) return src; + r->b = dict_; cap = walk(src); wrapped = c == '('; if(wrapped) src++, cap--;