From e504998b0301d17c262ab13134fc42311f9d73fc Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 8 Oct 2016 08:47:23 +0200 Subject: [PATCH] assq: use while instead of recursion. --- mes.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mes.c b/mes.c index cb6d1ab3..1052acf4 100644 --- a/mes.c +++ b/mes.c @@ -142,15 +142,18 @@ cons (scm *x, scm *y) return p; } +#define EQ_P(x, y)\ + ((x == y \ + || (x->type == CHAR && y->type == CHAR \ + && x->value == y->value) \ + || (x->type == NUMBER && y->type == NUMBER \ + && x->value == y->value)) \ + ? &scm_t : &scm_f) + scm * eq_p (scm *x, scm *y) { - return (x == y - || (x->type == CHAR && y->type == CHAR - && x->value == y->value) - || (x->type == NUMBER && y->type == NUMBER - && x->value == y->value)) - ? &scm_t : &scm_f; + return EQ_P (x, y); } scm * @@ -162,7 +165,7 @@ macro_p (scm *x) scm * null_p (scm *x) { - return eq_p (x, &scm_nil); + return x == &scm_nil ? &scm_t : &scm_f; } scm * @@ -285,15 +288,14 @@ pairlis (scm *x, scm *y, scm *a) scm * assq (scm *x, scm *a) { + while (a != &scm_nil && EQ_P (x, a->car->car) == &scm_f) a = a->cdr; if (a == &scm_nil) { #if DEBUG printf ("alist miss: %s\n", x->name); #endif return &scm_f; } - if (eq_p (caar (a), x) == &scm_t) - return car (a); - return assq (x, cdr (a)); + return a->car; } scm *