RFR: 8316426: Optimization for HexFormat.formatHex

Roger Riggs rriggs at openjdk.org
Mon Sep 18 19:17:46 UTC 2023


On Fri, 15 Sep 2023 18:04:29 GMT, 温绍锦 <duke at openjdk.org> wrote:

> In the improvement of @cl4es PR #15591, the advantages of non-lookup-table were discussed.
> 
> But if the input is byte[], using lookup table can improve performance.
> 
> For HexFormat#formatHex(Appendable, byte[]) and HexFormat#formatHex(byte[]), If the length of byte[] is larger, the performance of table lookup will be improved more obviously.

src/java.base/share/classes/jdk/internal/util/HexDigits.java line 101:

> 99:     public static short digitPair(int i) {
> 100:         return DIGITS[i & 0xff];
> 101:     }

DigitPair(i) appears to be unused and is redundant with DigitPair(i,boolean).

src/java.base/share/classes/jdk/internal/util/HexDigits.java line 112:

> 110:         short v = DIGITS[i & 0xff];
> 111:         return ucase
> 112:                 ? (short) (v & ~((v & 0b0100_0000_0100_0000) >> 1)) // really: to uppper

Clever but perhaps ('a' - 'A') to make it clearer where the constant came from

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15768#discussion_r1329173096
PR Review Comment: https://git.openjdk.org/jdk/pull/15768#discussion_r1329067559


More information about the core-libs-dev mailing list