develooper Front page | perl.datetime | Postings from March 2017

small DateTime optimization

Thread Next
Flavio S. Glock
March 15, 2017 14:13
small DateTime optimization
Message ID:
We've been using this patch at work for years, and I just forgot to
contribute it back. I hope you find it worth applying.

I believe the typical use case was:

  my $dt = $param || DateTime->now();

In this case $param is used in boolean context, which makes a fallback call
to _stringify(). With the patch, "boolean" just returns true.

The stringification change is a micro-optimization, it is not that

        # optimize boolean and string
        use overload
                '""'  => sub {
                               $_[0]->ymd('-') . 'T' . $_[0]->hms(':')
                bool  => sub { 1 },

                '<=>' => '_compare_overload',
                'cmp' => '_compare_overload',
                '-'   => '_subtract_overload',
                '+'   => '_add_overload',
                fallback   => 1;

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About