Skip to content
Permalink
Browse files

Make basic argument checking on DateTime.later a lot faster

Improves performance of DateTime.later with about 15%, mostly because
of a lot less allocations.
  • Loading branch information...
lizmat committed Nov 11, 2018
1 parent c03e71d commit 11cb4facf0947b1e741e74312d77c2d00801405c
Showing with 14 additions and 5 deletions.
  1. +14 −5 src/core/DateTime.pm6
@@ -278,12 +278,21 @@ my class DateTime does Dateish {
method hh-mm-ss() { sprintf "%02d:%02d:%02d", $!hour,$!minute,$!second }

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;
# 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;

# work on instant (tai)

0 comments on commit 11cb4fa

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