racket/contract: improve fast-append
test whether the 2nd arg is null once, rather than N times
This commit is contained in:
parent
721ef2050f
commit
a13070f302
|
@ -217,11 +217,12 @@
|
||||||
;; A specialized version of append that will immediately return if either
|
;; A specialized version of append that will immediately return if either
|
||||||
;; argument is empty
|
;; argument is empty
|
||||||
(define (fast-append l1 l2)
|
(define (fast-append l1 l2)
|
||||||
(cond
|
(if (null? l2)
|
||||||
[(null? l2) l1]
|
l1
|
||||||
[(null? l1) l2]
|
(let fast-append ((l1 l1))
|
||||||
[else
|
(if (null? l1)
|
||||||
(cons (car l1) (fast-append (cdr l1) l2))]))
|
l2
|
||||||
|
(cons (car l1) (fast-append (cdr l1)))))))
|
||||||
|
|
||||||
;; Assuming that merging is symmetric, ie old-can-merge? iff new-can-merge?
|
;; Assuming that merging is symmetric, ie old-can-merge? iff new-can-merge?
|
||||||
;; This is true of the current c-c implementation, but if it ever changes
|
;; This is true of the current c-c implementation, but if it ever changes
|
||||||
|
|
Loading…
Reference in New Issue
Block a user