Use `apply apply' which is slightly faster for most inputs than using
`list*'. (And add specialized cases for small inputs.)
This commit is contained in:
parent
be84425bd0
commit
da1c334f70
|
@ -157,7 +157,10 @@
|
||||||
|
|
||||||
(define append*
|
(define append*
|
||||||
(case-lambda [(ls) (apply append ls)] ; optimize common case
|
(case-lambda [(ls) (apply append ls)] ; optimize common case
|
||||||
[(l . lss) (apply append (apply list* l lss))]))
|
[(l1 l2) (apply append l1 l2)]
|
||||||
|
[(l1 l2 l3) (apply append l1 l2 l3)]
|
||||||
|
[(l1 l2 l3 l4) (apply append l1 l2 l3 l4)]
|
||||||
|
[(l . lss) (apply apply append l lss)]))
|
||||||
|
|
||||||
(define (flatten orig-sexp)
|
(define (flatten orig-sexp)
|
||||||
(let loop ([sexp orig-sexp] [acc null])
|
(let loop ([sexp orig-sexp] [acc null])
|
||||||
|
|
|
@ -4,7 +4,11 @@
|
||||||
|
|
||||||
(define string-append*
|
(define string-append*
|
||||||
(case-lambda [(strs) (apply string-append strs)] ; optimize common case
|
(case-lambda [(strs) (apply string-append strs)] ; optimize common case
|
||||||
[(str . strss) (apply string-append (apply list* str strss))]))
|
[(s1 strs) (apply string-append s1 strs)]
|
||||||
|
[(s1 s2 strs) (apply string-append s1 s2 strs)]
|
||||||
|
[(s1 s2 s3 strs) (apply string-append s1 s2 s3 strs)]
|
||||||
|
[(s1 s2 s3 s4 strs) (apply string-append s1 s2 s3 s4 strs)]
|
||||||
|
[(str . strss) (apply apply string-append str strss)]))
|
||||||
|
|
||||||
(require (only-in scheme/list add-between))
|
(require (only-in scheme/list add-between))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user