Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
slightly optimize IO::Handle.lines
We do not need to check for the limit when it is Inf. Also use .DEFINITE
instead of .defined, which delegates directly to p6definite.
  • Loading branch information
FROGGS committed Apr 21, 2014
1 parent 2528d63 commit 9605613
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/IO.pm
Expand Up @@ -180,9 +180,16 @@ my class IO::Handle does IO::FileTestable {
}

method lines($limit = $Inf) {
my $count = 0;
gather while ++$count <= $limit && (my $line = self.get).defined {
take $line;
if $limit == $Inf {
gather while (my $line = self.get).DEFINITE {
take $line;
}
}
else {
my $count = 0;
gather while ++$count <= $limit && (my $line = self.get).DEFINITE {
take $line;
}
}
}

Expand Down

0 comments on commit 9605613

Please sign in to comment.