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

Shaojin Wen swen at openjdk.org
Thu Oct 16 23:45:17 UTC 2025


This PR refactors the Double.toHexString method to improve its performance by eliminating the use of StringBuilder and regex operations. The new implementation uses a direct byte array approach to construct the hex string representation, which avoids the overhead of StringBuilder operations and regex pattern matching.

Existing tests in `java/lang/Double/ToHexString.java` cover the float conversions too.

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

Commit messages:
 - copyright
 - copyright
 - speed up Double.toHexString
 - add toHexString benchmark

Changes: https://git.openjdk.org/jdk/pull/27811/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27811&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8370013
  Stats: 91 lines in 2 files changed: 56 ins; 21 del; 14 mod
  Patch: https://git.openjdk.org/jdk/pull/27811.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27811/head:pull/27811

PR: https://git.openjdk.org/jdk/pull/27811


More information about the core-libs-dev mailing list