Skip to content

Commit

Permalink
Make Any.tail() use iterator's .count-only if available
Browse files Browse the repository at this point in the history
Makes, for example, %h.keys.tail 2.1x faster for a hash with 500_000 keys.
  • Loading branch information
zoffixznet committed Jun 22, 2017
1 parent bde2820 commit 9c04dfc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/Rakudo/Iterator.pm
Expand Up @@ -1901,9 +1901,17 @@ class Rakudo::Iterator {
X::Cannot::Lazy.new(:$action).throw,
nqp::stmts(
(my $result := IterationEnd),
nqp::until(
nqp::eqaddr((my $pulled := iterator.pull-one),IterationEnd),
($result := $pulled)
nqp::if(
nqp::can(iterator, 'count-only')
&& (my $count := iterator.count-only),
nqp::if(
iterator.skip-at-least($count - 1),
$result := iterator.pull-one
),
nqp::until(
nqp::eqaddr((my $pulled := iterator.pull-one),IterationEnd),
($result := $pulled)
),
),
$result
)
Expand Down

0 comments on commit 9c04dfc

Please sign in to comment.