mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8319423: Improve Year.isLeap by checking divisibility by 16
Reviewed-by: naoto, rriggs
This commit is contained in:
parent
59e9981ec2
commit
7d25f1c6cb
6 changed files with 125 additions and 7 deletions
|
@ -40,8 +40,12 @@ public final class CalendarUtils {
|
|||
* @see CalendarDate#isLeapYear
|
||||
*/
|
||||
public static boolean isGregorianLeapYear(int gregorianYear) {
|
||||
return (((gregorianYear % 4) == 0) && (((gregorianYear % 100) != 0)
|
||||
|| ((gregorianYear % 400) == 0)));
|
||||
// A year that is a multiple of 100, 200 and 300 is not divisible by 16, but 400 is.
|
||||
// So for a year that's divisible by 4, checking that it's also divisible by 16
|
||||
// is sufficient to determine it must be a leap year.
|
||||
return (gregorianYear & 15) == 0
|
||||
? (gregorianYear & 3) == 0
|
||||
: (gregorianYear & 3) == 0 && gregorianYear % 100 != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -929,7 +929,7 @@ public final class ZoneInfoFile {
|
|||
}
|
||||
|
||||
static final boolean isLeapYear(int year) {
|
||||
return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0);
|
||||
return CalendarUtils.isGregorianLeapYear(year);
|
||||
}
|
||||
|
||||
static final int lengthOfMonth(int year, int month) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue