RFR: 8316426: Optimization for HexFormat.formatHex
温绍锦
duke at openjdk.org
Tue Sep 19 01:38:50 UTC 2023
On Mon, 18 Sep 2023 19:08:14 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/HexFormat.java line 422:
>>
>>> 420: toHexDigits(out, bytes[fromIndex + i]);
>>> 421: }
>>> 422: out.append(suffix);
>>
>> Maybe change this whole `else` block to
>>
>> for (int i = 0; i < length; i++) {
>> if (i > 0)
>> out.append(delimiter);
>> out.append(prefix);
>> toHexDigits(out, bytes[fromIndex + i]);
>> out.append(suffix);
>> }
>>
>> for clarity?
>
> The original (and current) is coded to avoid a condition inside the loop.
I also think that the way of writing for_0 combined with if > 0 is easier to understand, The operation overhead of if > 0 is very small, and it will not affect performance when used in a loop.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15768#discussion_r1329453524
More information about the core-libs-dev
mailing list