<i18n dev> RFR: 8268469: Update java.time to use switch expressions [v3]
Stephen Colebourne
scolebourne at openjdk.java.net
Wed Jun 16 11:06:43 UTC 2021
On Wed, 16 Jun 2021 10:57:07 GMT, Patrick Concannon <pconcannon at openjdk.org> wrote:
>> Hi,
>>
>> Could someone please review my code for updating the code in the `java.time` packages to make use of the switch expressions?
>>
>> Kind regards,
>> Patrick
>
> Patrick Concannon has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
>
> - 8268469: Removed excessive spacing; corrected misplaced comments
> - Merge remote-tracking branch 'origin/master' into JDK-8268469
> - Merge remote-tracking branch 'origin/master' into JDK-8268469
> - 8268469: Update java.time to use switch expressions
src/java.base/share/classes/java/time/LocalDate.java line 607:
> 605: if (field instanceof ChronoField chronoField) {
> 606: if (chronoField.isDateBased()) {
> 607: int n = switch (chronoField) {
This logic is harder to read than before, and it requires the CPU to perform an extra branch on `(n == -1)`. It should just be a `return switch ...`
src/java.base/share/classes/java/time/LocalDateTime.java line 1181:
> 1179: if (unit instanceof ChronoUnit chronoUnit) {
> 1180: return switch (chronoUnit) {
> 1181: case NANOS -> plusNanos(amountToAdd);
Still has unnecessary alignment
There are lots of cases in the PR where `->` is still aligned. I'd like to see all of them unaligned.
src/java.base/share/classes/java/time/Month.java line 480:
> 478: int leap = leapYear ? 1 : 0;
> 479: return switch (this) {
> 480: case JANUARY -> 1;
Unnecessary alignment
-------------
PR: https://git.openjdk.java.net/jdk/pull/4433
More information about the i18n-dev
mailing list