Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement push-all for IO::Handle.lines
"words".IO.lines.elems.say                20% faster
"words".IO.lines(:!chomp).elems.say       35% faster
my @A = "words".IO.lines; say +@A         18% faster

This for a file with 235886 lines.
  • Loading branch information
lizmat committed Sep 14, 2015
1 parent 29cffa2 commit e11a341
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core/IO/Handle.pm
Expand Up @@ -360,6 +360,18 @@ my class IO::Handle does IO {
nqp::p6box_s(nqp::readlinefh($!PIO)).chomp
}
}
method push-all($target) {
my int $ins;
until nqp::eoffh($!PIO) {
$target.push(
nqp::p6box_s(nqp::readlinefh($!PIO)).chomp
);
$ins = $ins + 1;
}
nqp::bindattr_i($!handle, IO::Handle, '$!ins', $ins );
$!handle.close if $!close;
IterationEnd
}
}.new(self, $close));
}
else {
Expand All @@ -375,6 +387,16 @@ my class IO::Handle does IO {
nqp::p6box_s(nqp::readlinefh($!PIO))
}
}
method push-all($target) {
my int $ins;
until nqp::eoffh($!PIO) {
$target.push(nqp::readlinefh($!PIO));
$ins = $ins + 1;
}
nqp::bindattr_i($!handle, IO::Handle, '$!ins', $ins );
$!handle.close if $!close;
IterationEnd
}
}.new(self, $close));
}
}
Expand Down

0 comments on commit e11a341

Please sign in to comment.