Skip to content

Commit

Permalink
Restructure IO::Path.slurp a bit
Browse files Browse the repository at this point in the history
- mostly for readability, using ternaries instead of nqp::if
- don't store the blob in the method, pass it on as is
  • Loading branch information
lizmat committed May 15, 2020
1 parent 5b4faed commit 799d627
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/core.c/IO/Path.pm6
Expand Up @@ -589,14 +589,14 @@ my class IO::Path is Cool does IO {
# We use an IO::Handle in binary mode, and then decode the string
# all in one go, which avoids the overhead of setting up streaming
# decoding.
nqp::if(
nqp::istype((my $handle := IO::Handle.new(:path(self)).open(:bin)), Failure),
$handle,
nqp::stmts(
(my $blob := $handle.slurp(:close)),
nqp::if($bin, $blob, nqp::join("\n",
nqp::split("\r\n", $blob.decode: $enc || 'utf-8')))
))
my $handle := IO::Handle.new(:path(self)).open(:bin);
nqp::istype($handle,Failure)
?? $handle
!! $bin
?? $handle.slurp(:close)
!! nqp::join("\n",nqp::split("\r\n",
$handle.slurp(:close).decode: $enc || 'utf-8'
))
}

method spurt(IO::Path:D: $data, :$enc, :$append, :$createonly) {
Expand Down

0 comments on commit 799d627

Please sign in to comment.