RFR: 8316662: Remove one allocation per conversion in Double.toString(double) and Float.toString(float) [v2]
Chen Liang
liach at openjdk.org
Thu Dec 5 05:11:43 UTC 2024
On Fri, 29 Sep 2023 18:51:07 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> Raffaello Giulietti has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Uppercase JLA.
>
> src/java.base/share/classes/jdk/internal/math/FloatToDecimal.java line 508:
>
>> 506: try {
>> 507: return JLA.newStringNoRepl(bytes, StandardCharsets.ISO_8859_1);
>> 508: } catch (CharacterCodingException e) {
>
> I want to know why newStringNoRepl throws CharacterCodingException instead of IllegalArgumentException. The place where I use it is forced to write redundant try_catch code.
`newStringNoRepl` is originally intended to decode byte and throw an exception instead of putting a `?` when there is encoding error. By chance, it does not copy the input array if the input array is compatible as backing storage. As a result, we use it as "avoid copying" which has deviated from its initial purpose.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15861#discussion_r1870634083
More information about the core-libs-dev
mailing list