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

optimize isGregorianLeap #5972

Merged
merged 1 commit into from
Nov 13, 2019
Merged
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
9 changes: 8 additions & 1 deletion core/src/main/java/org/jruby/ext/date/RubyDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,14 @@ private static boolean isJulianLeap(final long year) {
// All years divisible by 4 are leap years in the Gregorian calendar,
// except for years divisible by 100 and not by 400.
private static boolean isGregorianLeap(final long year) {
return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
long uy = (year >= 0) ? year : -year;
if ((uy & 3) != 0)
return false;

long century = uy / 100;
if (uy != century * 100)
return true;
return (century & 3) == 0;
}

@JRubyMethod(name = "leap?")
Expand Down