RFR: 8378698: Optimize Base64.Encoder#encodeToString

Eirik Bjørsnøs eirbjo at openjdk.org
Thu Feb 26 10:20:45 UTC 2026


On Wed, 25 Feb 2026 15:37:02 GMT, Patrick Strawderman <duke at openjdk.org> wrote:

> Avoid a byte array copy in encodeToString by using JavaLangAccess#uncheckedNewStringWithLatin1Bytes

src/java.base/share/classes/java/util/Base64.java line 351:

> 349:          */
> 350:         public String encodeToString(byte[] src) {
> 351:             byte[] encoded = encode(src);

Consider adding a comment here to make it clear that `encoded` is guaranteed to be ASCII-only.

Otherwise, using `uncheckedNewStringWithLatin1Bytes` would not be safe. Better to make this contract explicit with a comment.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29920#discussion_r2858168126


More information about the core-libs-dev mailing list