Skip to content

Commit

Permalink
Make spurt() a few % faster
Browse files Browse the repository at this point in the history
Mostly because of fewer object allocations by adding specific candidates.
This should also help introspection and catch typos in the named parameters
at compile time.
  • Loading branch information
lizmat committed May 17, 2020
1 parent 7571f65 commit da5825e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/core.c/io_operators.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,35 @@ multi sub close(Channel:D $channel) { $channel.close }

proto sub slurp(|) {*}
multi sub slurp(*%_) { $*ARGFILES.slurp(|%_) }
multi sub slurp(IO::Handle:D $fh, *%_) { $fh.slurp(|%_) }
multi sub slurp(IO::Handle:D $fh, *%_) { $fh.slurp(|%_) }
multi sub slurp(IO() $path, :$bin!) { $path.slurp(:$bin) }
multi sub slurp(IO() $path, :$enc!) { $path.slurp(:$enc) }
multi sub slurp(IO() $path, :$enc ) { $path.slurp(:$enc) }
multi sub slurp(IO() $path ) { $path.slurp(:enc<utf8>) }

proto sub spurt($, $, |) {*}
multi sub spurt(IO::Handle:D $fh, $data, *%_) { $fh.spurt($data, |%_) }
multi sub spurt(IO() $path, $data, *%_) { $path.spurt($data, |%_) }
# Don't do anything special for the IO::Handle, as using spurt() as a sub
# when you've gone through the trouble of creating an IO::Handle, is not
# so likely, as you would probably just call the .spurt method on the handle.
multi sub spurt(IO::Handle:D $fh, $data, *%_) is default {
$fh.spurt($data, |%_)
}
multi sub spurt(IO() $path, Blob:D \data, :$append!) {
$path.spurt(data, :$append)
}
multi sub spurt(IO() $path, Blob:D \data, :$createonly!) {
$path.spurt(data, :$createonly)
}
multi sub spurt(IO() $path, Blob:D \data) {
$path.spurt(data)
}
multi sub spurt(IO() $path, \text, :$append!, :$enc) {
$path.spurt(text, :$append, :$enc)
}
multi sub spurt(IO() $path, \text, :$createonly!, :$enc) {
$path.spurt(text, :$createonly, :$enc)
}
multi sub spurt(IO() $path, \text, :$enc!) { $path.spurt(text, :$enc) }
multi sub spurt(IO() $path, \text ) { $path.spurt(text, :enc<utf8>) }

{
sub chdir(IO() $path) {
Expand Down

0 comments on commit da5825e

Please sign in to comment.