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)
|
||||
ac
|
||||
(die 'append "not a proper list" ls)))))
|
||||
(define revcons
|
||||
(define rev!
|
||||
(lambda (ls ac)
|
||||
(cond
|
||||
[(null? ls) ac]
|
||||
[else
|
||||
(revcons ($cdr ls) (cons ($car ls) ac))])))
|
||||
(let ([ls^ ($cdr ls)])
|
||||
($set-cdr! ls ac)
|
||||
(rev! ls^ ls))])))
|
||||
(define append1
|
||||
(lambda (ls ls*)
|
||||
(cond
|
||||
[(null? ls*) ls]
|
||||
[else
|
||||
(revcons (reverse ls ls ls '())
|
||||
(rev! (reverse ls ls ls '())
|
||||
(append1 ($car ls*) ($cdr ls*)))])))
|
||||
(define append
|
||||
(case-lambda
|
||||
|
|
|
@ -1 +1 @@
|
|||
1246
|
||||
1248
|
||||
|
|
Loading…
Reference in New Issue