diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 06:58:32 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 16:17:20 -0800 |
commit | 793c8c17c163a48c993e1adcb3defd4762e22a26 (patch) | |
tree | cdf9ff662dce93b081d9a0f69d971daa60ae949b | |
parent | 56383bfeeb21fe07a6d1fd17470148f72a2db7b1 (diff) | |
download | txr-793c8c17c163a48c993e1adcb3defd4762e22a26.tar.gz txr-793c8c17c163a48c993e1adcb3defd4762e22a26.tar.bz2 txr-793c8c17c163a48c993e1adcb3defd4762e22a26.zip |
Combat spurious retention in few more functions.
* lib.c (sub_list, replace_list): Use original list
variable instead of copying it to iter. Use gc_hint on list so
that the old value doesn't hang around on the stack, while a
register copy marches through the list.
-rw-r--r-- | lib.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -1057,25 +1057,27 @@ val sub_list(val list, val from, val to) else if (!null_or_missing_p(to) && lt(to, zero)) to = plus(to, if3(len, len, len = length(list))); + gc_hint(list); + if (to && from && gt(from, to)) { return nil; } else if (!to || (len && ge(to, len))) { - val iter, i; + val i; - for (i = zero, iter = list; iter; iter = cdr(iter), i = plus(i, one)) { + for (i = zero; list; list = cdr(list), i = plus(i, one)) { if (from && ge(i, from)) break; } - return iter; + return list; } else { - val iter, i; + val i; list_collect_decl (out, ptail); - for (i = zero, iter = list; iter; iter = cdr(iter), i = plus(i, one)) { + for (i = zero; list; list = cdr(list), i = plus(i, one)) { if (ge(i, to)) break; if (from && ge(i, from)) - ptail = list_collect(ptail, car(iter)); + ptail = list_collect(ptail, car(list)); } return out; @@ -1155,17 +1157,19 @@ val replace_list(val list, val items, val from, val to) if (to && lt(to, zero)) to = plus(to, len ? len : (len = length(list))); + gc_hint(list); + if (!to || (len && ge(to, len))) { if (from && zerop(from)) { return (listp(items)) ? items : list_vec(items); } else { - val iter, i; + val i; list_collect_decl (out, ptail); - for (i = zero, iter = list; iter; iter = cdr(iter), i = plus(i, one)) { + for (i = zero; list; list = cdr(list), i = plus(i, one)) { if (from && ge(i, from)) break; - ptail = list_collect(ptail, car(iter)); + ptail = list_collect(ptail, car(list)); } ptail = list_collect_nconc(ptail, if3(listp(items), @@ -1173,19 +1177,19 @@ val replace_list(val list, val items, val from, val to) return out; } } else { - val iter, i; + val i; list_collect_decl (out, ptail); - for (i = zero, iter = list; iter; iter = cdr(iter), i = plus(i, one)) { + for (i = zero; list; list = cdr(list), i = plus(i, one)) { if (ge(i, to)) break; if (from && lt(i, from)) - ptail = list_collect(ptail, car(iter)); + ptail = list_collect(ptail, car(list)); } ptail = list_collect_nconc(ptail, append2(if3(listp(items), items, list_vec(items)), - iter)); + list)); return out; } } |