Skip to content

Commit

Permalink
Prevent $*OUT lookup for each eigenstate with put / print
Browse files Browse the repository at this point in the history
Although one probably shouldn't print or put a Junction, having a
dynamic variable lookup for each eigenstate can be pretty expensive.
Also, convert to calling .print immediately, for better interface
with custom classes acting like $*OUT.
  • Loading branch information
lizmat committed May 11, 2020
1 parent 9a583dc commit 4297cb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/core.c/IO/Handle.pm6
Expand Up @@ -655,7 +655,9 @@ my class IO::Handle {
self.print(sprintf |c);
}

multi method print(Junction:D \j) { j.THREAD: { self.print: $_ } }
multi method print(IO::Handle:D: Junction:D \j) {
j.THREAD: { self.print: $_ }
}
multi method print(IO::Handle:D: Str:D \x --> True) {
$!decoder
?? self.WRITE($!encoder.encode-chars(x))
Expand All @@ -678,7 +680,9 @@ my class IO::Handle {
}
}

multi method put(Junction:D \j) { j.THREAD: { self.put: $_ } }
multi method put(IO::Handle:D: Junction:D \j) {
j.THREAD: { self.print: nqp::concat(.Str,$!nl-out) }
}
multi method put(IO::Handle:D: --> True) {
$!decoder
?? self.WRITE($!encoder.encode-chars($!nl-out))
Expand Down
8 changes: 6 additions & 2 deletions src/core.c/io_operators.pm6
Expand Up @@ -2,7 +2,10 @@ my class IO::ArgFiles { ... }

proto sub print(|) {*}
multi sub print(--> True) { } # nothing to do
multi sub print(Junction:D \j) { j.THREAD(&print) }
multi sub print(Junction:D \j) {
my $out := $*OUT;
j.THREAD: { $out.print: .Str }
}
multi sub print(Str:D \x) { $*OUT.print(x) }
multi sub print(\x) { $*OUT.print(x.Str) }
multi sub print(|) {
Expand Down Expand Up @@ -35,7 +38,8 @@ multi sub put() {
.print: .nl-out
}
multi sub put(Junction:D \j) {
j.THREAD(&put)
my $out := $*OUT;
j.THREAD: { $out.print: nqp::concat(.Str,$out.nl-out) }
}
multi sub put(\x) {
$_ := $*OUT;
Expand Down

0 comments on commit 4297cb0

Please sign in to comment.