db4
Slava Pestov 2008-07-15 22:58:45 -05:00
parent 19919bb130
commit 696a80367f
1 changed files with 17 additions and 5 deletions

View File

@ -24,11 +24,23 @@ TUPLE: merge
{ to2 array-capacity } ; { to2 array-capacity } ;
: dump ( from to seq accum -- ) : dump ( from to seq accum -- )
#! Optimize common case where to - from = 1. #! Optimize common case where to - from = 1, 2, or 3.
>r >r 2dup swap - 1 = >r >r 2dup swap - dup 1 =
[ drop r> nth-unsafe r> push ] [ 2drop r> nth-unsafe r> push ] [
[ r> <slice> r> push-all ] dup 2 = [
if ; inline 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 : l-elt [ from1>> ] [ seq>> ] bi nth-unsafe ; inline
: r-elt [ from2>> ] [ seq>> ] bi nth-unsafe ; inline : r-elt [ from2>> ] [ seq>> ] bi nth-unsafe ; inline