io.random: bit faster using set-nth-unsafe.

db4
John Benediktsson 2012-10-23 19:30:20 -07:00
parent a0d1c036ea
commit f835bb01f4
1 changed files with 7 additions and 7 deletions

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license ! See http://factorcode.org/license.txt for BSD license
USING: combinators fry io kernel locals math math.order random USING: combinators fry io kernel locals math math.order random
sequences ; sequences sequences.private ;
IN: io.random IN: io.random
@ -19,10 +19,10 @@ PRIVATE>
:: random-lines ( n -- lines ) :: random-lines ( n -- lines )
V{ } clone :> accum V{ } clone :> accum
[| line line# | [| line line# |
line# n <=> { line# n <= [
{ +lt+ [ line accum push ] } line accum push
{ +eq+ [ line accum [ push ] [ randomize drop ] bi ] } ] [
{ +gt+ [ line# random :> r line# random :> r
r n < [ line r accum set-nth ] when ] } r n < [ line r accum set-nth-unsafe ] when
} case ] if
] each-numbered-line accum ; ] each-numbered-line accum ;