Permalink
Browse files

Make Any.tail() use iterator's .count-only if available

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 9c04dfc4a427da11f5762534e4601fe697b9e127
Showing with 11 additions and 3 deletions.
  1. +11 −3 src/core/Rakudo/Iterator.pm
@@ -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
)

0 comments on commit 9c04dfc

Please sign in to comment.