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:
Eli Barzilay 2011-06-14 13:21:28 -04:00
parent be84425bd0
commit da1c334f70
2 changed files with 9 additions and 2 deletions

View File

@ -157,7 +157,10 @@
(define append*
(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)
(let loop ([sexp orig-sexp] [acc null])

View File

@ -4,7 +4,11 @@
(define string-append*
(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))