]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: faster "flip", looks at each element only once.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Sep 2012 23:02:20 +0000 (16:02 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Sep 2012 23:02:20 +0000 (16:02 -0700)
core/sequences/sequences.factor

index bd01a3bf79cd4c98624331ad9101c5000ecdc488..528aad620a19c9913b0c88a733f2b34a159e3035 100644 (file)
@@ -1010,7 +1010,10 @@ M: object sum 0 [ + ] binary-reduce ; inline
 <PRIVATE
 
 : generic-flip ( matrix -- newmatrix )
-    [ dup first length [ length min ] reduce iota ] keep
+    [
+        [ first-unsafe length 1 ] keep
+        [ length min ] (each) (each-integer) iota
+    ] keep
     [ [ nth-unsafe ] with { } map-as ] curry { } map-as ; inline
 
 USE: arrays
@@ -1020,7 +1023,10 @@ USE: arrays
 
 : array-flip ( matrix -- newmatrix )
     { array } declare
-    [ dup first array-length [ array-length min ] reduce iota ] keep
+    [
+        [ first-unsafe array-length 1 ] keep
+        [ array-length min ] (each) (each-integer) iota
+    ] keep
     [ [ { array } declare array-nth ] with { } map-as ] curry { } map-as ;
 
 PRIVATE>