Permalink
Browse files

Make $*KERNEL.signal 64% faster, overall

First call faster by: 628.50x (Signal arg),
    70% (Str arg), 3.78x (overall), (no change for Int arg)

Cached calls: 10.46x (Signal arg),
    14% (Str arg), 64% (overall), (no change for Int arg)
  • Loading branch information...
zoffixznet committed Jun 2, 2017
1 parent b879060 commit 79b8ab9d3f9a5499e8a7859f34b4499fb352ac13
Showing with 9 additions and 12 deletions.
  1. +9 −12 src/core/Kernel.pm
@@ -135,22 +135,19 @@ class Kernel does Systemic {
proto method signal (|) { * }
multi method signal(Kernel:D: Str:D $signal --> Int:D) {
once {
%!signals_by_Str =
@.signals.pairs.grep(*.value.defined).map({~$_.value => +.key});
nqp::stmts(
(my int $els = @!signals.elems),
(my int $i = -1),
nqp::while(
nqp::isgt_i($els, $i = nqp::add_i($i, 1)),
($_ := @!signals.AT-POS($i)).defined
&& %!signals_by_Str.ASSIGN-KEY(.Str, nqp::decont($i))))
}
%!signals_by_Str{$signal} // %!signals_by_Str{"SIG$signal"} // Int;
}

has %!signals_by_Signal;
multi method signal(Kernel:D: Signal:D $signal --> Int:D) {
once {
%!signals_by_Signal =
@.signals.pairs.grep(*.value.defined).map({~$_.value.WHICH => +.key});
}
%!signals_by_Signal{$signal.WHICH} // Int;
}

multi method signal(Kernel:D: Int:D $signal --> Int:D) { $signal }
multi method signal(Kernel:D: Signal:D \signal --> Int:D) { signal.value }
multi method signal(Kernel:D: Int:D \signal --> Int:D) { signal }
}

Rakudo::Internals.REGISTER-DYNAMIC: '$*KERNEL', {

0 comments on commit 79b8ab9

Please sign in to comment.