8283996: Reduce cost of year and month calculations
Reviewed-by: bpb, scolebourne, naoto, rriggs
This commit is contained in:
parent
45d4d7da23
commit
1a5f5da050
@ -363,9 +363,14 @@ public final class LocalDate
|
||||
|
||||
// convert march-based values back to january-based
|
||||
int marchMonth0 = (marchDoy0 * 5 + 2) / 153;
|
||||
int month = (marchMonth0 + 2) % 12 + 1;
|
||||
int month = marchMonth0 + 3;
|
||||
if (month > 12) {
|
||||
month -= 12;
|
||||
}
|
||||
int dom = marchDoy0 - (marchMonth0 * 306 + 5) / 10 + 1;
|
||||
yearEst += marchMonth0 / 10;
|
||||
if (marchDoy0 >= 306) {
|
||||
yearEst++;
|
||||
}
|
||||
|
||||
return new LocalDate((int)yearEst, month, dom);
|
||||
}
|
||||
|
@ -974,11 +974,11 @@ public final class ZoneRules implements Serializable {
|
||||
doyEst = zeroDay - (365 * yearEst + yearEst / 4 - yearEst / 100 + yearEst / 400);
|
||||
}
|
||||
yearEst += adjust; // reset any negative year
|
||||
int marchDoy0 = (int) doyEst;
|
||||
|
||||
// convert march-based values back to january-based
|
||||
int marchMonth0 = (marchDoy0 * 5 + 2) / 153;
|
||||
yearEst += marchMonth0 / 10;
|
||||
// convert march-based values back to january-based, adjust year
|
||||
if (doyEst >= 306) {
|
||||
yearEst++;
|
||||
}
|
||||
|
||||
// Cap to the max value
|
||||
return (int)Math.min(yearEst, Year.MAX_VALUE);
|
||||
|
Loading…
Reference in New Issue
Block a user