1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-03 13:20:26 +02:00

Minor for-each speedup

* module/ice-9/boot-9.scm (for-each): Minor speedup by unrolling
  tortoise/hare loop.
This commit is contained in:
Andy Wingo 2014-01-28 22:28:08 +01:00
parent 024a60e374
commit 8dcabf6003

View file

@ -840,19 +840,18 @@ information is unavailable."
(define for-each
(case-lambda
((f l)
(let for-each1 ((hare l) (tortoise l) (move? #f))
(let for-each1 ((hare l) (tortoise l))
(if (pair? hare)
(if move?
(if (eq? tortoise hare)
(scm-error 'wrong-type-arg "for-each" "Circular list: ~S"
(list l) #f)
(begin
(f (car hare))
(let ((hare (cdr hare)))
(if (pair? hare)
(begin
(when (eq? tortoise hare)
(scm-error 'wrong-type-arg "for-each" "Circular list: ~S"
(list l) #f))
(f (car hare))
(for-each1 (cdr hare) (cdr tortoise) #f)))
(begin
(f (car hare))
(for-each1 (cdr hare) tortoise #t)))
(for-each1 (cdr hare) (cdr tortoise))))))
(if (not (null? hare))
(scm-error 'wrong-type-arg "for-each" "Not a list: ~S"
(list l) #f)))))