diff options
author | Andy Wingo <wingo@pobox.com> | 2014-03-02 12:38:32 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2014-03-16 19:41:51 +0100 |
commit | f87a7327a54e10ec3ed77a6192a0cd38fed3a9c9 (patch) | |
tree | 117fd45adbdc6c81c9539fc6b9d73efd3e2ee8c8 /module/srfi/srfi-1.scm | |
parent | c2379a5b45a493c35ea90d64857a59e7832466be (diff) | |
download | guile-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.scm | 22 |
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) |