RFR: 8351443: Improve robustness of StringBuilder [v7]
Raffaello Giulietti
rgiulietti at openjdk.org
Fri May 9 15:57:57 UTC 2025
On Fri, 9 May 2025 13:28:44 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Add an assert to inflateToUTF16 method
>> Add doc of preconditions to appendChars... methods
>> Correct misc javadoc
>
> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1901:
>
>> 1899: }
>> 1900: return value;
>> 1901: }
>
> I think the logic can be simplified, without a need for the loop.
>
> private static byte[] putCharsAt(byte[] value, byte coder, int count, int index, char[] s, int off, int end) {
> if (isLatin1(coder)) {
> int latin1Len = StringUTF16.compress(s, off, value, index, end - off);
> if (latin1Len < end - off) {
> value = inflateToUTF16(value, count);
> StringUTF16.putCharsSB(value, index + latin1Len, s, off + latin1Len, end);
> }
> } else {
> StringUTF16.putCharsSB(value, index, s, off, end);
> }
> return value;
> }
Unfortunately, my simplification isn't sound when `s` is concurrently modified.
Please disregard.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24967#discussion_r2081978097
More information about the core-libs-dev
mailing list