We propose a new package-private static method in String, newStringLatin1NoRepl, which is shared via JLA. It creates a Latin-1 string from the trusted byte array, or if compact string is disabled, inflates the array and creates a string with UTF-16 coder.
Rationale:
1. Latin-1 case has a special logic used in multiple places even within String itself; pulling it out can simplify code much.
2. Most usages of newStringNoRepl via JLA is in `HexFormat` and is ISO_8859_1, which is Latin-1. The only other usage is one in `Files`, taking a Charset argument from user input. The replacement of newStringNoRepl with newStringLatin1NoRepl avoids going through extra logic and meaningless catch blocks in the source code. (There's a similar newStringUTF8NoRepl, which justifies the existence of a Latin1 version)
Rationale:
1. Latin-1 case has a special logic used in multiple places even within String itself; pulling it out can simplify code much.
2. Most usages of newStringNoRepl via JLA is in `HexFormat` and is ISO_8859_1, which is Latin-1. The only other usage is one in `Files`, taking a Charset argument from user input. The replacement of newStringNoRepl with newStringLatin1NoRepl avoids going through extra logic and meaningless catch blocks in the source code. (There's a similar newStringUTF8NoRepl, which justifies the existence of a Latin1 version)
- duplicates
-
JDK-8332079 String.getBytes with Charset to array or MemorySegment
-
- Open
-
- links to
-
Review openjdk/jdk/14655