Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created July 11, 2017 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizmat/a8c06dd75f07d15013735c71e4fabf11 to your computer and use it in GitHub Desktop.
Save lizmat/a8c06dd75f07d15013735c71e4fabf11 to your computer and use it in GitHub Desktop.
make say() about 10% faster
diff --git a/src/core/io_operators.pm b/src/core/io_operators.pm
index b34f74e..f820138 100644
--- a/src/core/io_operators.pm
+++ b/src/core/io_operators.pm
@@ -1,15 +1,16 @@
my class IO::ArgFiles { ... }
proto sub print(|) { * }
-multi sub print(Str:D \x) {
- $*OUT.print(x);
-}
-multi sub print(\x) {
- $*OUT.print(x.Str);
-}
+multi sub print() { $*OUT.print }
+multi sub print(Str:D \x) { $*OUT.print( x ) }
+multi sub print(\x) { $*OUT.print( x.Str ) }
multi sub print(**@args is raw) {
- my str $str;
- $str = nqp::concat($str,nqp::unbox_s(.Str)) for @args;
+ my str $str = '';
+ my $iter := @args.iterator;
+ nqp::until(
+ nqp::eqaddr(($_ := $iter.pull-one),IterationEnd),
+ $str = nqp::concat($str,.Str)
+ );
$*OUT.print($str);
}
@@ -18,59 +19,45 @@ multi sub print(**@args is raw) {
# instead call nqp::say directly.
proto sub say(|) { * }
-multi sub say() { $*OUT.print-nl }
-multi sub say(Str:D \x) {
- my $out := $*OUT;
- $out.print(nqp::concat(nqp::unbox_s(x),$out.nl-out));
-}
-multi sub say(\x) {
- my $out := $*OUT;
- $out.print(nqp::concat(nqp::unbox_s(x.gist),$out.nl-out));
-}
+multi sub say() { $*OUT.print-nl }
+multi sub say(Str:D \x) { $*OUT.say( x ) }
+multi sub say(\x) { $*OUT.say( x.gist ) }
multi sub say(**@args is raw) {
- my str $str;
+ my str $str = '';
my $iter := @args.iterator;
nqp::until(
- nqp::eqaddr(($_ := $iter.pull-one), IterationEnd),
- $str = nqp::concat($str, nqp::unbox_s(.gist)));
- my $out := $*OUT;
- $out.print(nqp::concat($str,$out.nl-out));
+ nqp::eqaddr(($_ := $iter.pull-one),IterationEnd),
+ $str = nqp::concat($str,.gist)
+ );
+ $*OUT.say($str)
}
proto sub put(|) { * }
-multi sub put() { $*OUT.print-nl }
-multi sub put(Str:D \x) {
- my $out := $*OUT;
- $out.print(nqp::concat(nqp::unbox_s(x),$out.nl-out));
-}
-multi sub put(\x) {
- my $out := $*OUT;
- $out.print(nqp::concat(nqp::unbox_s(x.Str),$out.nl-out));
-}
+multi sub put() { $*OUT.print-nl }
+multi sub put(Str:D \x) { $*OUT.put( x ) }
+multi sub put(\x) { $*OUT.put( x.Str ) }
multi sub put(**@args is raw) {
- my str $str;
+ my str $str = '';
my $iter := @args.iterator;
nqp::until(
- nqp::eqaddr(($_ := $iter.pull-one), IterationEnd),
- $str = nqp::concat($str, nqp::unbox_s(.Str)));
- my $out := $*OUT;
- $out.print(nqp::concat($str,$out.nl-out));
+ nqp::eqaddr(($_ := $iter.pull-one),IterationEnd),
+ $str = nqp::concat($str,.Str)
+ );
+ $*OUT.put($str)
}
proto sub note(|) { * }
-multi sub note() {
- my $err := $*ERR;
- $err.print(nqp::concat("Noted",$err.nl-out));
-}
-multi sub note(Str:D \x) {
- my $err := $*ERR;
- $err.print(nqp::concat(nqp::unbox_s(x),$err.nl-out));
-}
+multi sub note() { $*ERR.say("Noted") }
+multi sub note(Str:D \x) { $*ERR.say( x ) }
+multi sub note(\x) { $*ERR.say( x.gist ) }
multi sub note(**@args is raw) {
- my $err := $*ERR;
- my str $str;
- $str = nqp::concat($str,nqp::unbox_s(.gist)) for @args;
- $err.print(nqp::concat($str,$err.nl-out));
+ my str $str = '';
+ my $iter := @args.iterator;
+ nqp::until(
+ nqp::eqaddr(($_ := $iter.pull-one),IterationEnd),
+ $str = nqp::concat($str,.Str)
+ );
+ $*ERR.say($str)
}
sub gist(|) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment