From f6752238732c3d01da1ad4619fe626c4c1f42eeb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 29 Nov 2008 10:38:43 -0600 Subject: [PATCH] Minor optimization in unclip-slice --- core/sequences/sequences.factor | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index 832de612dd..118969bd3c 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -101,14 +101,17 @@ M: integer nth-unsafe drop ; INSTANCE: integer immutable-sequence +: first-unsafe + 0 swap nth-unsafe ; inline + : first2-unsafe - [ 0 swap nth-unsafe 1 ] [ nth-unsafe ] bi ; inline + [ first-unsafe ] [ 1 swap nth-unsafe ] bi ; inline : first3-unsafe - [ first2-unsafe 2 ] [ nth-unsafe ] bi ; inline + [ first2-unsafe ] [ 2 swap nth-unsafe ] bi ; inline : first4-unsafe - [ first3-unsafe 3 ] [ nth-unsafe ] bi ; inline + [ first3-unsafe ] [ 3 swap nth-unsafe ] bi ; inline : exchange-unsafe ( m n seq -- ) [ tuck [ nth-unsafe ] 2bi@ ] @@ -774,13 +777,13 @@ PRIVATE> tuck [ tail-slice ] 2bi@ ; : unclip ( seq -- rest first ) - [ rest ] [ first ] bi ; + [ rest ] [ first-unsafe ] bi ; : unclip-last ( seq -- butlast last ) [ but-last ] [ peek ] bi ; : unclip-slice ( seq -- rest-slice first ) - [ rest-slice ] [ first ] bi ; inline + [ rest-slice ] [ first-unsafe ] bi ; inline : 2unclip-slice ( seq1 seq2 -- rest-slice1 rest-slice2 first1 first2 ) [ unclip-slice ] bi@ swapd ; inline