RFR: 8301958: Avoid Arrays.copyOfRange overhead in java.lang.String [v3]
Claes Redestad
redestad at openjdk.org
Tue Feb 7 15:14:09 UTC 2023
On Tue, 7 Feb 2023 14:57:52 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Claes Redestad has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Update StringLatin1.trim for consistency
>
> src/java.base/share/classes/java/lang/String.java line 4546:
>
>> 4544: // To avoid surprises due to data races (which would either truncate or throw an exception)
>> 4545: // we should check that length <= val.length up front
>> 4546: checkOffset(length, val.length);
>
> I agree a check is needed here but I assume using checkOffset means that SB::toString could fail with SIOOBE. I wonder if Math.min(length, val.length) would be better here.
Ok. That keeps behavior consistent for most cases and removes a path where we can fail with SIOOBE in the existing code (down `StringUTF16::compress`).
-------------
PR: https://git.openjdk.org/jdk/pull/12453
More information about the core-libs-dev
mailing list