d6cc6af60002

Optimize FOR ... AROUND

Only bother counting if we actually need it.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 31 Aug 2020 12:02:39 -0400
parents e389a847e003
children 1aa2e5785e6f
branches/tags (none)
files src/iterate.lisp

Changes

--- a/src/iterate.lisp	Mon Aug 31 12:01:31 2020 -0400
+++ b/src/iterate.lisp	Mon Aug 31 12:02:39 2020 -0400
@@ -264,12 +264,14 @@
          (with ,source = ,original)
          (with ,is-list = (typep ,source 'list))
          (with ,len = (if ,is-list -1 (length ,source)))
-         (for ,i :from 0)
-         (,kwd ,var next (if ,is-list
-                           (progn (unless ,source (setf ,source ,original))
-                                  (pop ,source))
-                           (progn (when (= ,i ,len) (setf ,i 0))
-                                  (elt ,source ,i))))))))
+         (with ,i = -1)
+         (,kwd ,var :next (if ,is-list
+                            (progn (unless ,source (setf ,source ,original))
+                                   (pop ,source))
+                            (progn (incf ,i)
+                                   (when (= ,i ,len)
+                                     (setf ,i 0))
+                                   (elt ,source ,i))))))))
 
 
 (defclause-sequence ACROSS-FLAT-ARRAY INDEX-OF-FLAT-ARRAY