]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences.extras: faster join-with.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 15 Feb 2018 23:03:28 +0000 (15:03 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 15 Feb 2018 23:03:28 +0000 (15:03 -0800)
If we initialize the array with the glue, then we just set every
other element from the input sequence.

extra/sequences/extras/extras.factor

index 5b1e7b43947dfd7dbee71a64e98ba363f667e0fe..c1f2b232b0947fc70608c73444b807237f8a72bf 100644 (file)
@@ -627,6 +627,5 @@ PRIVATE>
     [ dup length ] unless* tail-slice ; inline
 
 : join-with ( seq glue -- newseq )
-    V{ } clone [
-        [ '[ _ _ push ] ] [ '[ _ push ] ] bi interleave
-    ] keep { } like ;
+    [ dup length dup 1 - + 0 max ] dip <array>
+    [ '[ 2 * _ set-nth-unsafe ] each-index ] keep ;