Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor slurp($filename) to use Parrot's .readall($filename);
this results in a massive speedup for slurping a file into a string.
See TT #1749 for related parrot details.
  • Loading branch information
pmichaud committed Sep 5, 2010
1 parent c7f6f27 commit 77a72a3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/IO.pm
Expand Up @@ -214,10 +214,13 @@ sub close($handle) {
}

sub slurp($filename) {
my $handle = open($filename, :r);
my $contents = $handle.slurp();
$handle.close();
$contents
## Although it's tempting to delegate to IO.slurp above, Parrot
## currently suffers a serious (25x) performance degradation when
## using readall() on an already-opened FileHandle. Much faster
## is to use readall($filename), which we do here. See TT #1749.
my $PIO = Q:PIR { %r = root_new['parrot';'FileHandle'] };
$PIO.encoding('utf8');
$PIO.readall($filename);
}
sub unlink($filename) {
Expand Down

0 comments on commit 77a72a3

Please sign in to comment.