Skip to content
Permalink
Browse files

Replace foo === Type with nqp::eqaddr(foo.WHAT,Type)

Which is *much* faster that === on account of not having to call a sub,
not having to wrap the result into a Bool, so a lot less allocating.
Makes Date.later about 30% faster, and other Date / DateTime related things
probably also significantly faster.
  • Loading branch information...
lizmat committed Nov 11, 2018
1 parent 18ded17 commit b463746daf51254bc5b8135af715d89be484bdd3
Showing with 6 additions and 6 deletions.
  1. +4 −4 src/core/Date.pm6
  2. +2 −2 src/core/DateTime.pm6
@@ -30,7 +30,7 @@ my class Date does Dateish {
:got($day),
:range("1..{self!DAYS-IN-MONTH($year,$month)}")
).throw;
self === Date
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($year,$month,$day,&formatter)
!! self.bless(:$year,:$month,:$day,:&formatter,|%_)
}
@@ -43,7 +43,7 @@ my class Date does Dateish {
:got($day),
:range("1..{self!DAYS-IN-MONTH($year,$month)}")
).throw;
self === Date
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($year,$month,$day,&formatter)
!! self.bless(:$year,:$month,:$day,:&formatter,|%_)
}
@@ -62,7 +62,7 @@ my class Date does Dateish {
self.new($0,$1,$2,:&formatter,|%_)
}
multi method new(Date: Dateish $d, :&formatter, *%_) {
self === Date
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($d.year,$d.month,$d.day,&formatter)
!! self.bless(
:year($d.year),
@@ -77,7 +77,7 @@ my class Date does Dateish {
}
method new-from-daycount($daycount,:&formatter) {
self!ymd-from-daycount($daycount, my $year, my $month, my $day);
self === Date
nqp::eqaddr(self.WHAT,Date)
?? nqp::create(self)!SET-SELF($year,$month,$day,&formatter,$daycount)
!! self.bless(:$year,:$month,:$day,:&formatter,:$daycount)
}
@@ -162,7 +162,7 @@ my class DateTime does Dateish {
my int $month = $m + 3 - 12 * ($m div 10);
my Int $year = $b * 100 + $d - 4800 + $m div 10;

my $dt = self === DateTime
my $dt = nqp::eqaddr(self.WHAT,DateTime)
?? ( %_ ?? die "Unexpected named parameter{"s" if %_ > 1} "
~ %_.keys.map({"`$_`"}).join(", ") ~ " passed. Were you "
~ "trying to use the named parameter form of .new() but "
@@ -237,7 +237,7 @@ my class DateTime does Dateish {
)
}
method !clone-without-validating(*%_) { # A premature optimization.
return self.clone(|%_) unless self === DateTime;
return self.clone(|%_) unless nqp::eqaddr(self.WHAT,DateTime);

my $h := nqp::getattr(%_,Map,'$!storage');
nqp::create(self)!SET-SELF(

0 comments on commit b463746

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