RFR: 8370013: Refactor Double.toHexString to eliminate regex and StringBuilder [v12]
Raffaello Giulietti
rgiulietti at openjdk.org
Tue Oct 21 07:31:09 UTC 2025
On Tue, 21 Oct 2025 07:22:47 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> Shaojin Wen has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 17 commits:
>>
>> - codestyle
>> - Merge remote-tracking branch 'upstream/master' into float_to_hex_str_2510
>>
>> # Conflicts:
>> # test/jdk/java/lang/Double/ToHexString.java
>> - copyright
>> - fix test, from @jddarcy
>> - extract doubleToLongBits, from @jddarcy
>> - fix test comment
>> - add tests for removed trailing zeros, from @jddarcy
>> - from @rgiulietti
>> - from @rgiulietti
>> - code style, from @rgiulietti
>> - ... and 7 more: https://git.openjdk.org/jdk/compare/eee29088...822c0259
>
> src/java.base/share/classes/java/lang/Double.java line 768:
>
>> 766: // Integer.digits maps values 0-15 to '0'-'f' characters
>> 767: chars[index++] = Integer.digits[((int)(signifBits >> ((12 - i) << 2))) & 0xF];
>> 768: }
>
> Suggestion:
>
> for (int sh = 48, end = 4 * trailingZeros; sh >= end; sh -= 4) {
> // Extract 4 bits at a time from left to right
> // Shift right by sh positions and mask with 0xF
> // Integer.digits maps values 0-15 to '0'-'f' characters
> chars[index++] = Integer.digits[((int)(signifBits >> sh)) & 0xF];
> }
Or even
for (int sh = 4 * 12, end = 4 * trailingZeros; sh >= end; sh -= 4) {
...
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27811#discussion_r2447019997
More information about the core-libs-dev
mailing list