Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace .?method by nqp::can(foo,"method") && foo.method
In the possibly hotter code paths.  This saves one method call, and in some
cases an hllization of 0/1.
  • Loading branch information
lizmat committed May 28, 2019
1 parent 2b0ac40 commit 7b10a42
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/core/Backtrace.pm6
Expand Up @@ -51,7 +51,11 @@ my class Backtrace::Frame {
} }


method is-hidden(Backtrace::Frame:D:) { method is-hidden(Backtrace::Frame:D:) {
?$!code.?is-hidden-from-backtrace nqp::if(
nqp::can($!code,"is-hidden-from-backtrace"),
$!code.is-hidden-from-backtrace,
False
)
} }
method is-routine(Backtrace::Frame:D:) { method is-routine(Backtrace::Frame:D:) {
nqp::hllbool(nqp::istype($!code,Routine)) nqp::hllbool(nqp::istype($!code,Routine))
Expand Down Expand Up @@ -212,7 +216,8 @@ my class Backtrace {
while self.AT-POS($idx++) -> $cand { while self.AT-POS($idx++) -> $cand {
next if $cand.is-hidden; # hidden is never interesting next if $cand.is-hidden; # hidden is never interesting
next if $noproto # no proto's please next if $noproto # no proto's please
&& $cand.code.?is_dispatcher; # if a dispatcher && nqp::can($cand,"is_dispatcher")
&& $cand.code.is_dispatcher; # if a dispatcher
next if !$setting # no settings please next if !$setting # no settings please
&& $cand.is-setting; # and in setting && $cand.is-setting; # and in setting


Expand Down
4 changes: 3 additions & 1 deletion src/core/CompUnit/RepositoryRegistry.pm6
Expand Up @@ -31,7 +31,9 @@ class CompUnit::RepositoryRegistry {
return CompUnit::Repository::Unknown.new(:path-spec($spec), :short-name($short-id)) return CompUnit::Repository::Unknown.new(:path-spec($spec), :short-name($short-id))
if so $class && nqp::istype($class, Failure) or !nqp::istype($class, CompUnit::Repository); if so $class && nqp::istype($class, Failure) or !nqp::istype($class, CompUnit::Repository);


my $abspath = $class.?absolutify($path) // $path; my $abspath = nqp::can($class,"absolutify")
?? $class.absolutify($path)
!! $path;
my $id = "$short-id#$abspath"; my $id = "$short-id#$abspath";
%options<next-repo> = $next-repo if $next-repo; %options<next-repo> = $next-repo if $next-repo;
$lock.protect( { $lock.protect( {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Distribution.pm6
Expand Up @@ -41,7 +41,7 @@ class CompUnit::Repository::Distribution does Distribution {
$meta<auth> //= $meta<authority> // $meta<author>; $meta<auth> //= $meta<authority> // $meta<author>;
$!meta = $meta; $!meta = $meta;


$!repo-name //= $!repo.name if ($!repo.?name // '') ne ''; $!repo-name //= $!repo.name if nqp::can($!repo,"name") && $!repo.name;
$!repo = $!repo.path-spec if $!repo.defined && $!repo !~~ Str; $!repo = $!repo.path-spec if $!repo.defined && $!repo !~~ Str;
} }


Expand Down
2 changes: 1 addition & 1 deletion src/core/Rakudo/Internals/JSON.pm6
Expand Up @@ -68,7 +68,7 @@ my class Rakudo::Internals::JSON {


if $obj ~~ Exception { if $obj ~~ Exception {
return $.to-json($obj.^name => Hash.new( return $.to-json($obj.^name => Hash.new(
(message => $obj.?message), (message => nqp::can($obj,"message") ?? $obj.message !! Nil),
$obj.^attributes.grep(*.has_accessor).map: { $obj.^attributes.grep(*.has_accessor).map: {
with .name.substr(2) -> $attr { with .name.substr(2) -> $attr {
$attr => ( $attr => (
Expand Down
4 changes: 3 additions & 1 deletion src/core/control.pm6
Expand Up @@ -140,7 +140,9 @@ sub samewith(|c) {
my $caller := nqp::getcodeobj(nqp::ctxcode($ctx)); my $caller := nqp::getcodeobj(nqp::ctxcode($ctx));
if nqp::istype($caller, Routine) { if nqp::istype($caller, Routine) {
if $caller.multi { if $caller.multi {
my $dispatcher := $caller.?dispatcher || die "Could not find dispatcher"; die "Could not find dispatcher"
unless my $dispatcher := nqp::can($caller,"dispatcher")
&& $caller.dispatcher;
return nqp::istype($caller, Method) return nqp::istype($caller, Method)
?? $dispatcher(nqp::atkey($ctx, 'self') // $caller.package,|c) ?? $dispatcher(nqp::atkey($ctx, 'self') // $caller.package,|c)
!! $dispatcher(|c); !! $dispatcher(|c);
Expand Down

0 comments on commit 7b10a42

Please sign in to comment.