Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make List.pick about 3% faster, brrt++
  • Loading branch information
lizmat committed Apr 24, 2015
1 parent 1905fc1 commit 5efcae8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/List.pm
Expand Up @@ -196,14 +196,14 @@ my class List does Positional { # declared in BOOTSTRAP
return self.AT-POS($elems.rand.floor) if $n == 1;

my Mu $rpa := nqp::clone($!items);
my int $i;
my Int $i;
gather while $n {
$i = nqp::rand_I(nqp::decont($elems), Int);
$elems = $elems - 1;
$n = $n - 1;
take-rw nqp::atpos($rpa,$i);
take-rw nqp::atpos($rpa,nqp::unbox_i($i));
# replace selected element with last unpicked one
nqp::bindpos($rpa,$i,nqp::atpos($rpa,nqp::unbox_i($elems)));
nqp::bindpos($rpa,nqp::unbox_i($i),nqp::atpos($rpa,nqp::unbox_i($elems)));
}
}

Expand Down

0 comments on commit 5efcae8

Please sign in to comment.