-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8372353: API to compute the byte length of a String encoded in a given Charset #28454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back cushon! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
| if (bytesCompatible(cs)) { | ||
| return value.length; | ||
| } | ||
| return getBytes(cs).length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the BOM‑less UTF‑16 charsets, this can simply return value.length << (1 ‑ coder())1:
| return getBytes(cs).length; | |
| if (cs instanceof sun.nio.cs.UTF_16LE || | |
| cs instanceof sun.nio.cs.UTF_16BE) { | |
| return value.length << (1 - coder()); | |
| } | |
| return getBytes(cs).length; |
Footnotes
-
Lone surrogates get replaced with
U+FFFDwhen encoding to UTF‑16 byString::getBytes(Charset), and all of LATIN1 can be encoded in UTF‑16. ↩
| while (stringData.length() < stringLength) { | ||
| stringData += (char) (Math.random() * 26) + 'a'; | ||
| } | ||
| stringData += c; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe avoid creating intermediate strings in a loop to avoid excess GC pressure?
| while (stringData.length() < stringLength) { | |
| stringData += (char) (Math.random() * 26) + 'a'; | |
| } | |
| stringData += c; | |
| var stringDataBuilder = new StringBuilder(stringLength + 1); | |
| while (stringDataBuilder.length() < stringLength) { | |
| stringDataBuilder.append((char) (Math.random() * 26) + 'a'); | |
| } | |
| stringData = stringDataBuilder.append(c).toString(); |
This implements an API to return the byte length of a String encoded in a given charset. See JDK-8372353 for background.
Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28454/head:pull/28454$ git checkout pull/28454Update a local copy of the PR:
$ git checkout pull/28454$ git pull https://git.openjdk.org/jdk.git pull/28454/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28454View PR using the GUI difftool:
$ git pr show -t 28454Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28454.diff