1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Optimize two-list srfi-1 map

* module/srfi/srfi-1.scm (map): Optimize the two-list variant.
This commit is contained in:
Andy Wingo 2014-04-01 20:52:15 +02:00
parent 545274a035
commit f082c5f30a

View file

@ -572,6 +572,23 @@ has just one element then that's the return value."
(map1 (cdr in) (cons (f (car in)) out))
(reverse! out))))
((f l1 l2)
(check-arg procedure? f map)
(let* ((len1 (length+ l1))
(len2 (length+ l2))
(len (if (and len1 len2)
(min len1 len2)
(or len1 len2))))
(unless len
(scm-error 'wrong-type-arg "map"
"Args do not contain a proper (finite) list: ~S"
(list (list l1 l2)) #f))
(let map2 ((l1 l1) (l2 l2) (out '()) (len len))
(if (zero? len)
(reverse! out)
(map2 (cdr l1) (cdr l2)
(cons (f (car l1) (car l2)) out) (1- len))))))
((f l1 . rest)
(check-arg procedure? f map)
(let ((len (fold (lambda (ls len)