]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting.monotonic: a bit faster.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 17 Jul 2015 21:23:50 +0000 (14:23 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 17 Jul 2015 21:23:50 +0000 (14:23 -0700)
basis/splitting/monotonic/monotonic.factor

index 024a7e32fa966f08b9c43ecd46e7efa82bf49693..e4c075e38ed99f3b99b4ca90eb92acd188bc2c1d 100644 (file)
@@ -7,19 +7,19 @@ IN: splitting.monotonic
 <PRIVATE
 
 :: ((monotonic-split)) ( seq quot slice-quot n -- pieces )
-    V{ } clone :> accum
+    V{ } clone :> accum
 
-    0 seq [ ] [
+    0 seq [ ] [
         [ 1 + ] 2dip [
-            quot call [
-                [ seq slice-quot call accum push ] keep dup
-            ] unless
+            quot call [ dup accum push ] unless
         ] keep
     ] map-reduce drop
 
-    n = [ drop ] [ n seq slice-quot call accum push ] if
+    n = [ n accum push ] unless
 
-    accum { } like ; inline
+    accum dup rest-slice [
+        seq slice-quot call
+    ] { } 2map-as ; inline
 
 : (monotonic-split) ( seq quot slice-quot -- pieces )
     pick length [ 3drop { } ] [ ((monotonic-split)) ] if-zero ; inline