]> gitweb.factorcode.org Git - factor.git/commitdiff
splitting.monotonic: slightly faster.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 2 Jan 2022 23:46:06 +0000 (15:46 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 2 Jan 2022 23:46:06 +0000 (15:46 -0800)
basis/splitting/monotonic/monotonic.factor

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