From c2a1ea6748a4ddcac7c48898b525c90526736a31 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 11 Feb 2014 16:22:17 +0900 Subject: [PATCH] dont consume arena in pic_append --- src/pair.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pair.c b/src/pair.c index 80ac57a4..e461ba70 100644 --- a/src/pair.c +++ b/src/pair.c @@ -138,17 +138,17 @@ pic_value pic_append(pic_state *pic, pic_value xs, pic_value ys) { int ai = pic_gc_arena_preserve(pic); + pic_value x; - if (pic_nil_p(xs)) { - return ys; - } - else { - xs = pic_cons(pic, pic_car(pic, xs), pic_append(pic, pic_cdr(pic, xs), ys)); - } + xs = pic_reverse(pic, xs); + pic_for_each (x, xs) { + ys = pic_cons(pic, x, ys); - pic_gc_arena_restore(pic, ai); - pic_gc_protect(pic, xs); - return xs; + pic_gc_arena_restore(pic, ai); + pic_gc_protect(pic, xs); + pic_gc_protect(pic, ys); + } + return ys; } pic_value