From 696a80367f79682541ded03bacd435446421ec78 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 15 Jul 2008 22:58:45 -0500 Subject: [PATCH] Ricing --- core/sorting/sorting.factor | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/core/sorting/sorting.factor b/core/sorting/sorting.factor index a6bcf92651..a93a30e7f2 100755 --- a/core/sorting/sorting.factor +++ b/core/sorting/sorting.factor @@ -24,11 +24,23 @@ TUPLE: merge { to2 array-capacity } ; : dump ( from to seq accum -- ) - #! Optimize common case where to - from = 1. - >r >r 2dup swap - 1 = - [ drop r> nth-unsafe r> push ] - [ r> r> push-all ] - if ; inline + #! Optimize common case where to - from = 1, 2, or 3. + >r >r 2dup swap - dup 1 = + [ 2drop r> nth-unsafe r> push ] [ + dup 2 = [ + 2drop dup 1+ + r> [ nth-unsafe ] curry bi@ + r> [ push ] curry bi@ + ] [ + dup 3 = [ + 2drop dup 1+ dup 1+ + r> [ nth-unsafe ] curry tri@ + r> [ push ] curry tri@ + ] [ + drop r> subseq r> push-all + ] if + ] if + ] if ; inline : l-elt [ from1>> ] [ seq>> ] bi nth-unsafe ; inline : r-elt [ from2>> ] [ seq>> ] bi nth-unsafe ; inline