Skip to content

Commit

Permalink
Eliminate A Few Scalar Allocs For Push-All
Browse files Browse the repository at this point in the history
I could not measure a performance benefit
in the benchmark I had, but the bytecode
got a bit simpler and total allocation count
decreased a little.
  • Loading branch information
timo committed Dec 29, 2018
1 parent 2ce7956 commit 501231e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/core/Iterator.pm6
Expand Up @@ -52,10 +52,10 @@ my role Iterator {


# Has the iterator produce all of its values into the target. Typically # Has the iterator produce all of its values into the target. Typically
# called in .STORE if the iterator is non-lazy. Returns IterationEnd. # called in .STORE if the iterator is non-lazy. Returns IterationEnd.
method push-all($target --> IterationEnd) { method push-all(\target --> IterationEnd) {
nqp::until( # we may not .sink $pulled here, since it can be a Seq nqp::until( # we may not .sink $pulled here, since it can be a Seq
nqp::eqaddr((my $pulled := self.pull-one),IterationEnd), nqp::eqaddr((my \pulled := self.pull-one),IterationEnd),
$target.push($pulled) target.push(pulled)
) )
} }


Expand All @@ -66,10 +66,10 @@ my role Iterator {
# calls push-all. If all values the iterator can produce are pushed, then # calls push-all. If all values the iterator can produce are pushed, then
# IterationEnd should be returned. Otherwise, return something else (Mu # IterationEnd should be returned. Otherwise, return something else (Mu
# will do fine). # will do fine).
method push-until-lazy($target) { method push-until-lazy(\target) {
nqp::unless( nqp::unless(
self.is-lazy, self.is-lazy,
self.push-all($target) self.push-all(target)
) )
} }


Expand Down
6 changes: 3 additions & 3 deletions src/core/List.pm6
Expand Up @@ -630,14 +630,14 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
IterationEnd IterationEnd
} }


method push-until-lazy($target) { method push-until-lazy(\target) {
nqp::if( nqp::if(
nqp::isconcrete($!todo), nqp::isconcrete($!todo),
nqp::stmts( # something to reify still nqp::stmts( # something to reify still
(my int $elems = $!todo.reify-until-lazy), (my int $elems = $!todo.reify-until-lazy),
nqp::while( # doesn't sink nqp::while( # doesn't sink
nqp::islt_i($!i = nqp::add_i($!i,1),$elems), nqp::islt_i($!i = nqp::add_i($!i,1),$elems),
$target.push(nqp::atpos($!reified,$!i)) target.push(nqp::atpos($!reified,$!i))
), ),
nqp::if( nqp::if(
$!todo.fully-reified, $!todo.fully-reified,
Expand All @@ -652,7 +652,7 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
($elems = nqp::elems($!reified)), ($elems = nqp::elems($!reified)),
nqp::while( # doesn't sink nqp::while( # doesn't sink
nqp::islt_i($!i = nqp::add_i($!i,1),$elems), nqp::islt_i($!i = nqp::add_i($!i,1),$elems),
$target.push(nqp::atpos($!reified,$!i)) target.push(nqp::atpos($!reified,$!i))
), ),
IterationEnd IterationEnd
) )
Expand Down

0 comments on commit 501231e

Please sign in to comment.