From 05b2717b9ea5e799b268ac1f2ca6c0a413e33434 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 21 Nov 2013 06:32:56 -0800 Subject: [PATCH] less memory usage of pic_reverse --- src/pair.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pair.c b/src/pair.c index d3ebc772..c1c78af1 100644 --- a/src/pair.c +++ b/src/pair.c @@ -96,10 +96,16 @@ pic_length(pic_state *pic, pic_value obj) pic_value pic_reverse(pic_state *pic, pic_value list) { - pic_value v, acc = pic_nil_value(); + int ai = pic_gc_arena_preserve(pic); + pic_value v, acc; + acc = pic_nil_value(); for (v = list; ! pic_nil_p(v); v = pic_cdr(pic ,v)) { acc = pic_cons(pic, pic_car(pic, v), acc); + + pic_gc_arena_restore(pic, ai); + pic_gc_protect(pic, acc); + pic_gc_protect(pic, v); } return acc; }