From 5381baee858c3537d247cf0a636631672d0cd62f Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 22 Jan 2022 20:58:13 -0800 Subject: [PATCH] Revert "sequences: faster iteration over slices" This reverts commit 8657a568bb822c56d28063cab394094270cf71f9. --- basis/grouping/grouping.factor | 2 +- core/sequences/sequences.factor | 43 +++++++++------------------------ 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/basis/grouping/grouping.factor b/basis/grouping/grouping.factor index 49890180e0..750c8eea1e 100644 --- a/basis/grouping/grouping.factor +++ b/basis/grouping/grouping.factor @@ -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 diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index b1524145d4..610630053e 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -397,36 +397,15 @@ PRIVATE> > ] [ 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 ] 2dip 2map-as ; inline -- 2.34.1