On Tue, 15 Mar 2022 23:25:17 GMT, Claes Redestad <redes...@openjdk.org> wrote:

>> Xin Liu has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Change growOnly to maybeLatin.
>>   
>>   This patch also copys over the attribute from the other 
>> AbstractStringBuilder.
>>   Add a unit test to cover methods which cause maybeLatin1 becomes true.
>
> 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.

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

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

Reply via email to