]> gitweb.factorcode.org Git - factor.git/commitdiff
rosetta-code.multisplit: reduce memory usage
authorAlexander Iljin <ajsoft@yandex.ru>
Thu, 2 Apr 2020 01:15:26 +0000 (03:15 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 Apr 2020 01:50:01 +0000 (01:50 +0000)
Avoid creating a filtered sequence when all we need is its first element.

extra/rosetta-code/multisplit/multisplit.factor

index b082be912395b1d25dc2880e58ae95164c46e93b..cfe5583bc3d90138f82662356de23f999f3f999b 100644 (file)
@@ -8,7 +8,7 @@ IN: rosetta-code.multisplit
     over [ 2array ] [ 2drop f ] if ;
 
 : best-separator ( seq -- pos index )
-    dup [ first ] map infimum '[ first _ = ] filter first first2 ;
+    dup [ first ] map infimum '[ first _ = ] find nip first2 ;
 
 : first-subseq ( separators seq -- n separator )
     dupd [ swap [ subseq-start ] dip ?pair ] curry map-index sift