Permalink
Browse files

Manually inline swapping logic

For 35% faster permutations()
  • Loading branch information...
lizmat committed Jan 18, 2017
1 parent 4ae08e0 commit c64aeb32ddb2eda217e0da7cbf878135d4890909
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/core/Rakudo/Iterator.pm
@@ -1739,7 +1739,9 @@ class Rakudo::Iterator {
),
($l = nqp::sub_i($l,1))
),
self!swap($k,$l),
(my $tmp := nqp::atpos($!next,$k)),
nqp::bindpos($!next,$k,nqp::atpos($!next,$l)),
nqp::bindpos($!next,$l,$tmp)
)
),
($l = $!n),
@@ -1748,7 +1750,11 @@ class Rakudo::Iterator {
($k = nqp::add_i($k,1)),
($l = nqp::sub_i($l,1))
),
self!swap($k,$l)
nqp::stmts(
($tmp := nqp::atpos($!next,$k)),
nqp::bindpos($!next,$k,nqp::atpos($!next,$l)),
nqp::bindpos($!next,$l,$tmp)
)
),
nqp::if(
$b,
@@ -1760,11 +1766,6 @@ class Rakudo::Iterator {
IterationEnd
)
}
method !swap(int $k,int $l --> Nil) {
my $tmp := nqp::atpos($!next,$k);
nqp::bindpos($!next,$k,nqp::atpos($!next,$l));
nqp::bindpos($!next,$l,$tmp)
}
method count-only { $!elems }
method bool-only(--> True) { }
}.new($n,$b)

0 comments on commit c64aeb3

Please sign in to comment.