RFR: 8370013: Refactor Double.toHexString to eliminate regex and StringBuilder [v2]

Shaojin Wen swen at openjdk.org
Tue Oct 21 01:24:03 UTC 2025


On Mon, 20 Oct 2025 08:58:07 GMT, Andrew Haley <aph at openjdk.org> wrote:

>> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   from @jddarcy
>
> src/java.base/share/classes/java/lang/Double.java line 771:
> 
>> 769:                     // Shift right by (12 - i) * 4 positions and mask with 0xF
>> 770:                     // Integer.digits maps values 0-15 to '0'-'f' characters
>> 771:                     chars[index++] = Integer.digits[((int)(signifBits >> ((12 - i) << 2))) & 0xF];
> 
> Suggestion:
> 
>                     int digit = ((int)(signifBits >> ((12 - i) << 2))) & 0xF;
>                     chars[index++] = digit + digit < 10 ? '0' : 'a';

Keeping the same as Integer.toHexString/Long.toHexString, I think it is okay to continue using table lookup here. If we want to eliminate the table lookup, we can use vectorization to eliminate it. I have submitted another PR before https://github.com/openjdk/jdk/pull/22942

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27811#discussion_r2446493068


More information about the core-libs-dev mailing list