Skip to content
Permalink
Browse files

Make basic argument checking on DateTime.later a lot faster

Improves performance of Date.later with about 30%, mostly because
of a lot less allocations.
  • Loading branch information...
lizmat committed Nov 11, 2018
1 parent 0fa6988 commit 08fac0452f4be3e61b52c200c4a68db5a9207a0c
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/core/Date.pm6
@@ -104,12 +104,21 @@ my class Date does Dateish {
}

method later(:$earlier, *%unit) {
my @pairs = %unit.pairs;
die "More than one time unit supplied" if @pairs > 1;
die "No time unit supplied" unless @pairs;

my $unit = self!VALID-UNIT(@pairs.AT-POS(0).key);
my $amount = @pairs.AT-POS(0).value.Int;
# basic sanity check
nqp::if(
nqp::eqaddr(
(my \later := (my \iterator := %unit.iterator).pull-one),
IterationEnd
),
(die "No time unit supplied"),
nqp::unless(
nqp::eqaddr(iterator.pull-one,IterationEnd),
(die "More than one time unit supplied")
)
);
my $unit := later.key;
my $amount = later.value;
$amount = -$amount if $earlier;

if nqp::atkey($valid-units,$unit) -> $multiplier {

0 comments on commit 08fac04

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