Changed implementation of append so that it uses half the cons cells
that it previously used. Interestingly, this reduced bootstrap time by 60ms and 2 garbage collections! And I thought I did not use append :-).
This commit is contained in:
parent
8c0563b2d3
commit
c1a677ca4b
|
@ -145,18 +145,20 @@
|
||||||
(if (null? h)
|
(if (null? h)
|
||||||
ac
|
ac
|
||||||
(die 'append "not a proper list" ls)))))
|
(die 'append "not a proper list" ls)))))
|
||||||
(define revcons
|
(define rev!
|
||||||
(lambda (ls ac)
|
(lambda (ls ac)
|
||||||
(cond
|
(cond
|
||||||
[(null? ls) ac]
|
[(null? ls) ac]
|
||||||
[else
|
[else
|
||||||
(revcons ($cdr ls) (cons ($car ls) ac))])))
|
(let ([ls^ ($cdr ls)])
|
||||||
|
($set-cdr! ls ac)
|
||||||
|
(rev! ls^ ls))])))
|
||||||
(define append1
|
(define append1
|
||||||
(lambda (ls ls*)
|
(lambda (ls ls*)
|
||||||
(cond
|
(cond
|
||||||
[(null? ls*) ls]
|
[(null? ls*) ls]
|
||||||
[else
|
[else
|
||||||
(revcons (reverse ls ls ls '())
|
(rev! (reverse ls ls ls '())
|
||||||
(append1 ($car ls*) ($cdr ls*)))])))
|
(append1 ($car ls*) ($cdr ls*)))])))
|
||||||
(define append
|
(define append
|
||||||
(case-lambda
|
(case-lambda
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1246
|
1248
|
||||||
|
|
Loading…
Reference in New Issue