On Mon, 25 Sep 2023 12:28:06 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> 温绍锦 has updated the pull request incrementally with one additional commit >> since the last revision: >> >> fix logic error > > src/java.base/share/classes/java/util/Formatter.java line 2949: > >> 2947: } >> 2948: } else { >> 2949: if (first == '0') { > > While it's clever to avoid re-parsing I think it muddies the control flow. It > would be simpler if we always reset to `off = start; c = first` in this > `else` block then unconditionally call `parseFlags(); parseWidth();` outside > in `parse`. The few extra calls to `s.charAt(..)` this might add a little > overhead on some tests, but the JIT might like the brevity and less branchy > structure overall and on larger benchmarks.. Maybe worth experimenting with. Good idea. In addition, I also plan to simplify the writing of the for statement, such as: for (int size = 0; off < max; ++off, c = s.charAt(off), size++) { ==> for (int size = 0; off < max; c = s.charAt(++off), size++) { ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/15776#discussion_r1335909991