Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance Enhancement: compare once instead of twice #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Performance Enhancement: compare once instead of twice
DateTime spans comparisons are very expensive, and this PR enables
to cut their number in half in some cases.
  • Loading branch information
jafd committed Jul 11, 2020
commit ecdb0470a05d45a2fbaeea9c75247dfe30379a1e
5 changes: 3 additions & 2 deletions lib/DateTime/Span.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ sub from_datetimes {
( $end, $open_end ) = ( $args{end}, 0 ) if exists $args{end};
( $end, $open_end ) = ( $args{before}, 1 ) if exists $args{before};

if ( $start > $end ) {
my $cmpres = $start <=> $end;
if ( $cmpres > 0 ) { # $start > $end
die "Span cannot start after the end in DateTime::Span->from_datetimes\n";
}
$set = Set::Infinite::_recurrence->new( $start, $end );
if ( $start != $end ) {
if ( $cmpres != 0 ) { # $start != $end
# remove start, such that we have ">" instead of ">="
$set = $set->complement( $start ) if $open_start;
# remove end, such that we have "<" instead of "<="
Expand Down