Skip to content

Commit

Permalink
Make cloning a Date faster
Browse files Browse the repository at this point in the history
Use nqp::ifnull instead of existskey ?? atkey !! attribute combo.  Makes
Date.later about 15% faster, and probably other Date operations as well.
  • Loading branch information
lizmat committed Nov 11, 2018
1 parent 08fac04 commit 98d07cf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/core/Date.pm6
Expand Up @@ -147,19 +147,18 @@ my class Date does Dateish {
method clone(*%_) {
my $h := nqp::getattr(%_,Map,'$!storage');
self.new(
nqp::existskey($h,'year') ?? nqp::atkey($h,'year') !! $!year,
nqp::existskey($h,'month') ?? nqp::atkey($h,'month') !! $!month,
nqp::existskey($h,'day') ?? nqp::atkey($h,'day') !! $!day,
formatter => nqp::existskey($h,'formatter')
?? nqp::atkey($h,'formatter') !! &!formatter,
nqp::ifnull(nqp::atkey($h,'year'), $!year),
nqp::ifnull(nqp::atkey($h,'month'),$!month),
nqp::ifnull(nqp::atkey($h,'day'), $!day),
formatter => nqp::ifnull(nqp::atkey($h,'formatter'),&!formatter),
)
}
method !clone-without-validating(*%_) { # A premature optimization.
my $h := nqp::getattr(%_,Map,'$!storage');
nqp::create(self)!SET-SELF(
nqp::existskey($h,'year') ?? nqp::atkey($h,'year') !! $!year,
nqp::existskey($h,'month') ?? nqp::atkey($h,'month') !! $!month,
nqp::existskey($h,'day') ?? nqp::atkey($h,'day') !! $!day,
nqp::ifnull(nqp::atkey($h,'year'), $!year),
nqp::ifnull(nqp::atkey($h,'month'),$!month),
nqp::ifnull(nqp::atkey($h,'day'), $!day),
&!formatter,
)
}
Expand Down

0 comments on commit 98d07cf

Please sign in to comment.