less memory usage of pic_reverse

This commit is contained in:
Yuichi Nishiwaki 2013-11-21 06:32:56 -08:00
parent 00fc0ee931
commit 05b2717b9e
1 changed files with 7 additions and 1 deletions

View File

@ -96,10 +96,16 @@ pic_length(pic_state *pic, pic_value obj)
pic_value pic_value
pic_reverse(pic_state *pic, pic_value list) 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)) { for (v = list; ! pic_nil_p(v); v = pic_cdr(pic ,v)) {
acc = pic_cons(pic, pic_car(pic, v), acc); 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; return acc;
} }