Skip to content

Commit

Permalink
Make R:It:ReifiedArray 15% to 30% faster
Browse files Browse the repository at this point in the history
- make sure pull-one is as simple as possible
- add a !hole method for handling holes in $!reified
- make push-all also use !hole method
- use lexical $i in push-all for slighly faster performance
  • Loading branch information
lizmat committed Dec 5, 2017
1 parent c5afc97 commit a974de9
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/core/Rakudo/Iterator.pm
Expand Up @@ -2414,17 +2414,20 @@ class Rakudo::Iterator {
}
method new(\arr, Mu \des) { nqp::create(self)!SET-SELF(arr, des) }

method !hole(int $i) is raw {
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindpos($!reified,$i,v) }
)
}
method pull-one() is raw {
nqp::ifnull(
nqp::atpos($!reified,$!i = nqp::add_i($!i,1)),
nqp::if(
nqp::islt_i($!i,nqp::elems($!reified)), # found a hole
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindpos($!reified,$!i,v) }
),
self!hole($!i),
IterationEnd
)
)
Expand All @@ -2433,18 +2436,14 @@ class Rakudo::Iterator {
method push-all($target --> IterationEnd) {
nqp::stmts(
(my int $elems = nqp::elems($!reified)),
(my int $i = $!i),
nqp::while( # doesn't sink
nqp::islt_i($!i = nqp::add_i($!i,1),$elems),
$target.push(nqp::ifnull(
nqp::atpos($!reified,$!i),
nqp::p6bindattrinvres(
(my \v := nqp::p6scalarfromdesc($!descriptor)),
Scalar,
'$!whence',
-> { nqp::bindpos($!reified,$!i,v) }
)
))
)
nqp::islt_i($i = nqp::add_i($i,1),$elems),
$target.push(
nqp::ifnull(nqp::atpos($!reified,$i),self!hole($i))
)
),
($!i = $i)
)
}
method skip-one() {
Expand Down

0 comments on commit a974de9

Please sign in to comment.