summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-09-07 05:04:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-09-07 05:04:51 -0700
commit13bba10fb47fa1b3638021120042641464f0c57a (patch)
tree18bc9d8f26b6f00d5edbc149041e7fadb3001061
parent337e47fb140beea69af30d3e8f84307ee244afb4 (diff)
downloadtxr-13bba10fb47fa1b3638021120042641464f0c57a.tar.gz
txr-13bba10fb47fa1b3638021120042641464f0c57a.tar.bz2
txr-13bba10fb47fa1b3638021120042641464f0c57a.zip
digits/digpow: recycle temporary conses.
* arith.c (digcommon): Improved termination test in the second loop to avoid wasteful pop when the list of powers is empty. Use rcyc_pop to recycle these conses; they will be immediately reused for building the output list.
-rw-r--r--arith.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/arith.c b/arith.c
index 6079e15f..a5d0d8f1 100644
--- a/arith.c
+++ b/arith.c
@@ -3729,7 +3729,7 @@ static val digcommon(int pow, val self, val n, val base_in)
{
val k = r;
- val p = nil, p0;
+ val p = nil;
list_collect_decl (out, ptail);
while (le(k, n)) {
@@ -3737,7 +3737,8 @@ static val digcommon(int pow, val self, val n, val base_in)
k = mul(k, r);
}
- while ((p0 = pop(&p))) {
+ while (p) {
+ val p0 = rcyc_pop(&p);
cnum i = 0;
while (ge(n, p0)) {
i++;