unoidl2

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/unoidl2.git/
Log | Files | Refs

commit 0cc11334c93bfb095fb88fe06d7f808888d9c89f
parent c61c8326110cfe3639af0f60b0f946ef19a0b443
Author: Tomas Hlavaty <tom@logand.com>
Date:   Tue, 13 Mar 2012 23:25:26 +0100

better intern1

Diffstat:
Munoidl2.c | 23+++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/unoidl2.c b/unoidl2.c @@ -64,21 +64,19 @@ Any cons(Any car, Any cdr) { return x; } -static Any root1 = NULL; +static Any root1; +static Any intern1_k; Any intern1(char *x) { - if(x) { - Any root = root1; - while(*x) { - Any c = mkchara(*x++); // TODO no consing - Any root2 = find(c, cdr(root), equal, caar); - if(NIL == root2) - root->u.c.cdr = cons(root2 = list1(cons(c, root)), cdr(root)); - root = root2; - } - return root; + Any p = root1; + for(; *x; x++) { + intern1_k->u.chara = *x; + Any r = find(intern1_k, cdr(p), equal, caar); + if(NIL == r) + p->u.c.cdr = cons(r = list1(cons(mkchara(*x), p)), cdr(p)); + p = r; } - return NIL; + return p; } Any mk(Kind kind, char *token) { @@ -260,6 +258,7 @@ void init() { NIL->u.c.car = NIL; NIL->u.c.cdr = NIL; root1 = list1(NIL); + intern1_k = mkchara(0); T = xalloc(); T->tag = TOKEN; T->u.t.kind = 0;