On Sat, 29 Jun 2024 16:16:51 GMT, David Schlosnagle <d...@openjdk.org> wrote:
>> Shaojin Wen has updated the pull request incrementally with one additional >> commit since the last revision: >> >> rename `digit` to `width` > > src/java.base/share/classes/java/lang/StringFormat.java line 82: > >> 80: conv = format.charAt(off + 2); >> 81: } >> 82: } > > is it worth handling `width > 9`? > > Suggestion: > > for (int i = 2; conv >= '1' && conv <= '9' && off + i < max; i++) { > width = (width * 10) + (conv - '0'); > if (off + i < max) { > conv = format.charAt(off + i); > } > } a quick local benchmark on 2021 MacBook M1 Pro before/after motivating this: @Benchmark public String wideStringIntFormat() { return "%123s %42d".formatted(s, i); } #### Before: Benchmark Mode Cnt Score Error Units StringFormat.wideStringIntFormat avgt 15 377.603 ± 85.742 ns/op #### After: Benchmark Mode Cnt Score Error Units StringFormat.wideStringIntFormat avgt 15 54.104 ± 0.079 ns/op ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19956#discussion_r1659916636