]> gitweb.factorcode.org Git - factor.git/commitdiff
Revert "sequences: faster iteration over slices"
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 23 Jan 2022 04:58:13 +0000 (20:58 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 23 Jan 2022 04:58:13 +0000 (20:58 -0800)
This reverts commit 8657a568bb822c56d28063cab394094270cf71f9.

basis/grouping/grouping.factor
core/sequences/sequences.factor

index 49890180e03d166d1227714629ca84c7cb94f05e..750c8eea1eae15341b474a3878619e31ed49b6ce 100644 (file)
@@ -74,7 +74,7 @@ PRIVATE>
         2 = [
             [ first2-unsafe ] dip call
         ] [
-            [ [ first-unsafe 1 ] [ setup-each [ + ] 2dip ] bi ] dip
+            [ [ first-unsafe 1 ] [ setup-each ] bi ] dip
             '[ @ _ keep swap ] (all-integers?) nip
         ] if
     ] if ; inline
index b1524145d4af27eedc2633a0935b9f25df5d784c..610630053e197f44e1c49830a89caab8b3893945 100644 (file)
@@ -397,36 +397,15 @@ PRIVATE>
 
 <PRIVATE
 
-! slow-each versions don't unslice
-
-: setup-slow-each ( seq -- n quot )
+: setup-each ( seq -- n quot )
     [ length check-length ] keep [ nth-unsafe ] curry ; inline
 
-: (slow-each) ( seq quot -- n quot' )
-    [ setup-slow-each ] dip compose ; inline
-
-: (slow-each-index) ( seq quot -- n quot' )
-    [ setup-slow-each [ keep ] curry ] dip compose ; inline
-
-: setup-each ( seq -- i n quot )
-    dup slice? [
-        [ from>> ] [ to>> ] [ seq>> ] tri
-    ] [
-        [ length check-length 0 swap ] keep
-    ] if [ nth-unsafe ] curry ; inline
-
-: (each) ( seq quot -- i n quot' )
+: (each) ( seq quot -- n quot' )
     [ setup-each ] dip compose ; inline
 
-: (each-from) ( seq quot i -- i n quot' )
-    [ (each) ] dip [ + ] curry 2dip ; inline
-
-: (each-index) ( seq quot -- i n quot' )
+: (each-index) ( seq quot -- n quot' )
     [ setup-each [ keep ] curry ] dip compose ; inline
 
-: (each-index-from) ( seq quot i -- i n quot' )
-    [ (each-index) ] dip [ + ] curry 2dip ; inline
-
 : (collect) ( quot into -- quot' )
     [ [ keep ] dip set-nth-unsafe ] 2curry ; inline
 
@@ -434,7 +413,7 @@ PRIVATE>
     (collect) each-integer ; inline
 
 : map-into ( seq quot into -- )
-    [ (slow-each) ] dip collect ; inline
+    [ (each) ] dip collect ; inline
 
 : 2nth-unsafe ( n seq1 seq2 -- elt1 elt2 )
     [ nth-unsafe ] bi-curry@ bi ; inline
@@ -459,7 +438,7 @@ PRIVATE>
     over [ dupd nth-unsafe ] [ drop f ] if ; inline
 
 : (find) ( seq quot quot' -- i elt )
-    pick [ [ (slow-each) ] dip call ] dip finish-find ; inline
+    pick [ [ (each) ] dip call ] dip finish-find ; inline
 
 : (find-from) ( n seq quot quot' -- i elt )
     [ 2dup bounds-check? ] 2dip
@@ -468,7 +447,7 @@ PRIVATE>
     if ; inline
 
 : (find-index) ( seq quot quot' -- i elt )
-    pick [ [ (slow-each-index) ] dip call ] dip finish-find ; inline
+    pick [ [ (each-index) ] dip call ] dip finish-find ; inline
 
 : (find-index-from) ( n seq quot quot' -- i elt )
     [ 2dup bounds-check? ] 2dip
@@ -485,10 +464,10 @@ PRIVATE>
 PRIVATE>
 
 : each ( ... seq quot: ( ... x -- ... ) -- ... )
-    (each) (each-integer) ; inline
+    (each) each-integer ; inline
 
 : each-from ( ... seq quot: ( ... x -- ... ) i -- ... )
-    (each-from) (each-integer) ; inline
+    -rot (each) (each-integer) ; inline
 
 : reduce ( ... seq identity quot: ( ... prev elt -- ... next ) -- ... result )
     swapd each ; inline
@@ -497,7 +476,7 @@ PRIVATE>
     overd [ [ collect ] keep ] new-like ; inline
 
 : map-as ( ... seq quot: ( ... elt -- ... newelt ) exemplar -- ... newseq )
-    [ (slow-each) ] dip map-integers ; inline
+    [ (each) ] dip map-integers ; inline
 
 : map ( ... seq quot: ( ... elt -- ... newelt ) -- ... newseq )
     over map-as ; inline
@@ -578,7 +557,7 @@ PRIVATE>
     [ find-integer ] (find-index) ; inline
 
 : all? ( ... seq quot: ( ... elt -- ... ? ) -- ... ? )
-    (each) (all-integers?) ; inline
+    (each) all-integers? ; inline
 
 : push-if ( ..a elt quot: ( ..a elt -- ..b ? ) accum -- ..b )
     [ keep ] dip rot [ push ] [ 2drop ] if ; inline
@@ -639,7 +618,7 @@ PRIVATE>
     [ dup ] swap [ keep ] curry produce nip ; inline
 
 : each-index ( ... seq quot: ( ... elt index -- ... ) -- ... )
-    (each-index) (each-integer) ; inline
+    (each-index) each-integer ; inline
 
 : map-index-as ( ... seq quot: ( ... elt index -- ... newelt ) exemplar -- ... newseq )
     [ dup length <iota> ] 2dip 2map-as ; inline