Skip to content
Permalink
Browse files

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 7b10a428a5565cf122218523c1bc28c14b3d63aa
@@ -51,7 +51,11 @@ my class Backtrace::Frame {
}

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:) {
nqp::hllbool(nqp::istype($!code,Routine))
@@ -212,7 +216,8 @@ my class Backtrace {
while self.AT-POS($idx++) -> $cand {
next if $cand.is-hidden; # hidden is never interesting
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
&& $cand.is-setting; # and in setting

@@ -31,7 +31,9 @@ class CompUnit::RepositoryRegistry {
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);

my $abspath = $class.?absolutify($path) // $path;
my $abspath = nqp::can($class,"absolutify")
?? $class.absolutify($path)
!! $path;
my $id = "$short-id#$abspath";
%options<next-repo> = $next-repo if $next-repo;
$lock.protect( {
@@ -41,7 +41,7 @@ class CompUnit::Repository::Distribution does Distribution {
$meta<auth> //= $meta<authority> // $meta<author>;
$!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;
}

@@ -68,7 +68,7 @@ my class Rakudo::Internals::JSON {

if $obj ~~ Exception {
return $.to-json($obj.^name => Hash.new(
(message => $obj.?message),
(message => nqp::can($obj,"message") ?? $obj.message !! Nil),
$obj.^attributes.grep(*.has_accessor).map: {
with .name.substr(2) -> $attr {
$attr => (
@@ -140,7 +140,9 @@ sub samewith(|c) {
my $caller := nqp::getcodeobj(nqp::ctxcode($ctx));
if nqp::istype($caller, Routine) {
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)
?? $dispatcher(nqp::atkey($ctx, 'self') // $caller.package,|c)
!! $dispatcher(|c);

0 comments on commit 7b10a42

Please sign in to comment.
You can’t perform that action at this time.