Skip to content
Permalink
Browse files

Make cloning a Date faster

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 98d07cf6f9c2dd27390d7e842ef7aaa47259271f
Showing with 7 additions and 8 deletions.
  1. +7 −8 src/core/Date.pm6
@@ -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,
)
}

0 comments on commit 98d07cf

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