summaryrefslogtreecommitdiff
path: root/module/srfi/srfi-1.scm
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2014-03-02 12:38:32 +0100
committerAndy Wingo <wingo@pobox.com>2014-03-16 19:41:51 +0100
commitf87a7327a54e10ec3ed77a6192a0cd38fed3a9c9 (patch)
tree117fd45adbdc6c81c9539fc6b9d73efd3e2ee8c8 /module/srfi/srfi-1.scm
parentc2379a5b45a493c35ea90d64857a59e7832466be (diff)
downloadguile-f87a7327a54e10ec3ed77a6192a0cd38fed3a9c9.tar.gz
More for-each micro-optimizations
* module/ice-9/boot-9.scm (for-each): * module/srfi/srfi-1.scm (for-each): Re-implement one-list case using an explicit check for list? instead of the tortoise-hare thing. Seems to be faster!
Diffstat (limited to 'module/srfi/srfi-1.scm')
-rw-r--r--module/srfi/srfi-1.scm22
1 files changed, 5 insertions, 17 deletions
diff --git a/module/srfi/srfi-1.scm b/module/srfi/srfi-1.scm
index 74b01bc93..fd0b55e9e 100644
--- a/module/srfi/srfi-1.scm
+++ b/module/srfi/srfi-1.scm
@@ -606,24 +606,12 @@ has just one element then that's the return value."
(case-lambda
((f l)
(check-arg procedure? f for-each)
- (let for-each1 ((hare l) (tortoise l))
- (if (pair? hare)
- (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)))
- (for-each1 hare tortoise))))
- (if (not (null? hare))
- (scm-error 'wrong-type-arg "for-each" "Not a list: ~S"
- (list l) #f)))))
+ (check-arg list? l for-each)
+ (let for-each1 ((l l))
+ (unless (null? l)
+ (f (car l))
+ (for-each1 (cdr l)))))
-
((f l1 . rest)
(check-arg procedure? f for-each)
(let ((len (fold (lambda (ls len)