Skip to content

Commit

Permalink
Speed up Dates.isleapyear by reordering exprs (#37988)
Browse files Browse the repository at this point in the history
In the common case that `y` is not factored by 4, this code performs one
comparison rather than two. The number of comparisons for the two other
cases are unchanged.
  • Loading branch information
cmcaine committed Oct 12, 2020
1 parent 8c03bf7 commit 1ef05e3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/Dates/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function totaldays(y, m, d)
end

# If the year is divisible by 4, except for every 100 years, except for every 400 years
isleapyear(y) = ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)
isleapyear(y) = (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0))

# Number of days in month
const DAYSINMONTH = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
Expand Down

0 comments on commit 1ef05e3

Please sign in to comment.