]> gitweb.factorcode.org Git - factor.git/commitdiff
sequences: bit faster binary-reduce.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 10 Sep 2012 23:48:40 +0000 (16:48 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 10 Sep 2012 23:53:10 +0000 (16:53 -0700)
core/sequences/sequences.factor

index 9b1c7b28e24523cd6f3081336908d6c6e5a4d2a1..fcae61044eb21a0c3ed71923694da41b4a81d67b 100644 (file)
@@ -864,18 +864,18 @@ PRIVATE>
 : nth3-unsafe ( n seq -- a b c )
     [ nth2-unsafe ] [ [ 2 + ] dip nth-unsafe ] 2bi ; inline
 
-: (binary-reduce) ( ... seq start quot: ( ... elt1 elt2 -- ... newelt ) from to -- ... value )
+: (binary-reduce) ( ... seq start quot: ( ... elt1 elt2 -- ... newelt ) from length -- ... value )
     #! We can't use case here since combinators depends on
     #! sequences
-    2dup swap - dup 4 < [
-        nip integer>fixnum {
+    dup 4 < [
+        integer>fixnum {
             [ 2drop nip ]
             [ 2nip swap nth-unsafe ]
             [ -rot [ drop swap nth2-unsafe ] dip call ]
             [ -rot [ drop swap nth3-unsafe ] dip bi@ ]
         } dispatch
     ] [
-        2/ over [ - dup ] dip
+        [ 2/ ] [ over - ] bi [ 2dup + ] dip
         [ (binary-reduce) ] [ 2curry ] curry 2bi@
         pick [ 3bi ] dip call
     ] if ; inline recursive