From b40f2ff54478fb9bb89c717d7234ede2d5750490 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 9 Jun 2014 17:53:16 -0700 Subject: [PATCH] sorting.quick: faster by using stack variables not mutable locals. --- extra/sorting/quick/quick.factor | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/extra/sorting/quick/quick.factor b/extra/sorting/quick/quick.factor index df8d935ddf..e585cb190f 100644 --- a/extra/sorting/quick/quick.factor +++ b/extra/sorting/quick/quick.factor @@ -10,24 +10,19 @@ IN: sorting.quick :: (quicksort) ( seq from to -- ) from to < [ - from to + 2/ :> p - from :> l! - to :> r! + from to + 2/ seq nth-unsafe :> pivot - p seq nth-unsafe :> p-nth - - [ l r <= ] [ - [ l seq nth-unsafe p-nth before? ] [ l 1 + l! ] while - [ r seq nth-unsafe p-nth after? ] [ r 1 - r! ] while - l r <= [ - l r seq exchange-unsafe - l 1 + l! - r 1 - r! + from to [ 2dup <= ] [ + [ over seq nth-unsafe pivot before? ] [ [ 1 + ] dip ] while + [ dup seq nth-unsafe pivot after? ] [ 1 - ] while + 2dup <= [ + [ seq exchange-unsafe ] + [ [ 1 + ] [ 1 - ] bi* ] 2bi ] when ] while - seq from r (quicksort) - seq l to (quicksort) + [ seq from ] dip (quicksort) + [ seq ] dip to (quicksort) ] when ; inline recursive