Skip to content

Conversation

@wenshao
Copy link
Contributor

@wenshao wenshao commented Oct 22, 2025

With the introduction of String.newStringWithLatin1Bytes, we can use it to simplify the toString methods of Integer and Long. By replacing the implementation that supports COMPACT_STRING = false with newStringWithLatin1Bytes, we gain the following benefits:

  1. Simplified implementation
  2. Strings with codeSize < 35 in Integer.toString(int) and Long.toString(long) can be inlined in C1, improving performance in early calls.

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8370503: Use String.newStringWithLatin1Bytes to simplify Integer/Long toString method (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27929/head:pull/27929
$ git checkout pull/27929

Update a local copy of the PR:
$ git checkout pull/27929
$ git pull https://git.openjdk.org/jdk.git pull/27929/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27929

View PR using the GUI difftool:
$ git pr show -t 27929

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27929.diff

Using Webrev

Link to Webrev Comment

…place conditional COMPACT_STRINGS checks with direct calls to\nString.newStringWithLatin1Bytes() for better code clarity and\nmaintainability. This change affects:\n\n- Integer.toString(int)\n- Integer.toUnsignedString0(int, int)\n- Long.toString(long)\n- Long.toUnsignedString0(long, int)\n\nThe new approach leverages the existing String.newStringWithLatin1Bytes()\nmethod which already handles the COMPACT_STRINGS logic internally.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 22, 2025

👋 Welcome back swen! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 22, 2025

@wenshao This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8370503: Use String.newStringWithLatin1Bytes to simplify Integer/Long toString method

Reviewed-by: rgiulietti, rriggs

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 33 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Oct 22, 2025
@openjdk
Copy link

openjdk bot commented Oct 22, 2025

@wenshao The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

formatUnsignedIntUTF16(val, shift, buf, chars);
return new String(buf, UTF16);
}
byte[] buf = new byte[chars];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the array size be chars*2 in when compact strings is not in use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to handle the case where COMPACT_STRING false is used, as it is inflate in java.lang.String#newStringWithLatin1Bytes.

@wenshao wenshao changed the title Simplify toString() implementations in Integer and Long Use String.newStringWithLatin1Bytes to simplify Integer/Long toString method Oct 23, 2025
@rgiulietti
Copy link
Contributor

Nice cleanup.

@wenshao wenshao changed the title Use String.newStringWithLatin1Bytes to simplify Integer/Long toString method 8370503: Use String.newStringWithLatin1Bytes to simplify Integer/Long toString method Oct 23, 2025
@wenshao wenshao marked this pull request as ready for review October 23, 2025 14:22
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 23, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 23, 2025

Webrevs

@rgiulietti
Copy link
Contributor

@wenshao Seems like Integer.formatUnsignedIntUTF16() is no longer needed.

@rgiulietti
Copy link
Contributor

Same for Long.formatUnsignedLong0UTF16()

Copy link
Contributor

@rgiulietti rgiulietti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenshao Thanks for the cleanup

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 23, 2025
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cleanup looks good.

@wenshao
Copy link
Contributor Author

wenshao commented Oct 24, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Oct 24, 2025

Going to push as commit fd23a61.
Since your change was applied there have been 46 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 24, 2025
@openjdk openjdk bot closed this Oct 24, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 24, 2025
@openjdk
Copy link

openjdk bot commented Oct 24, 2025

@wenshao Pushed as commit fd23a61.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants