On Tue, 22 Mar 2022 06:54:35 GMT, Xin Liu <x...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1008:
>> 
>>> 1006:         this.count = newCount;
>>> 1007:         putStringAt(start, str);
>>> 1008:         if (end - start > 0) {
>> 
>> regardless of value of `end - start` you could also skip setting 
>> `maybeLatin1 = true` if:
>> - `str.coder() == UTF16`
>> - `this.coder == LATIN1`
>
> hi, @cl4es, 
> you are correct for this and the comment at setCharAt(), but I don't think 
> it's necessary to check all cases. this attribute is just like a hint. if 
> this.coder == LATIN1, that it doesn't matter if maybeLatin1 is true. 
> 
> if our attitude is checking all cases, it will become too complex and 
> error-prone. deleteCharAt() and setLength() also need to check.  if so, it 
> will pollute code more. I incline to set this attribute conservatively in all 
> deleting methods.

Right, we don't need to check every case and I agree with favoring simplicity 
at the expense of some false positives. Perhaps the `if (end - start > 0) {` 
test here isn't pulling its weight either and we should just unconditionally 
set `maybeLatin1 = true` even if we're not actually replacing anything (which 
is very much a corner-case).

-------------

PR: https://git.openjdk.java.net/jdk/pull/7671

Reply via email to