From 3df89b1573d415bb18a912c4c774edc189b1ac11 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 15 May 2016 22:59:38 -0700 Subject: Some streamlining in the cons recycling. * lib.c (rcyc_pop): Just assume that *plist points to a cons and access the fields directly. (rcyc_cons): Don't bother with rplacd. (rcyc_list): Don't bother with set macro. * regex.c (read_until_match): Defensive coding: locally ensure that rcyc_pop won't be called on a nil stack, which will now segfault. --- lib.c | 18 ++++++++---------- regex.c | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib.c b/lib.c index 64a22b68..4b158752 100644 --- a/lib.c +++ b/lib.c @@ -605,8 +605,8 @@ val pop(val *plist) val rcyc_pop(val *plist) { val rcyc = *plist; - val ret = car(rcyc); - *plist = cdr(rcyc); + val ret = rcyc->c.car; + *plist = rcyc->c.cdr; rcyc_cons(rcyc); return ret; } @@ -2535,7 +2535,7 @@ val make_half_lazy_cons(val func, val car) void rcyc_cons(val cons) { - rplacd(cons, recycled_conses); + cons->c.cdr = recycled_conses; cons->c.car = nil; recycled_conses = cons; } @@ -2545,13 +2545,11 @@ void rcyc_list(val list) if (list) { val rl_orig = recycled_conses; recycled_conses = list; - for (; list; list = list->c.cdr) { - list->c.car = nil; - if (!list->c.cdr) { - set(mkloc(list->lc.cdr, list), rl_orig); - break; - } - } + + while (list->c.cdr) + list = list->c.cdr; + + list->c.cdr = rl_orig; } } diff --git a/regex.c b/regex.c index faf38965..4ad34dcf 100644 --- a/regex.c +++ b/regex.c @@ -2579,7 +2579,7 @@ val read_until_match(val regex, val stream_in, val include_match_in) if (nil) { out_match: - while (stack != match) + while (stack && stack != match) unget_char(rcyc_pop(&stack), stream); if (!out) out = null_string; -- cgit v1.2.3