RFR: 8273100: Improve AbstractStringBuilder.append(String) when using CompactStrings [v3]

Сергей Цыпанов github.com+10835776+stsypanov at openjdk.java.net
Mon Aug 30 15:21:31 UTC 2021


On Mon, 30 Aug 2021 14:52:12 GMT, Claes Redestad <redestad at openjdk.org> wrote:

>> What about lines 582, 1003 and 1175? E.g. 582
>> 
>> public AbstractStringBuilder append(String str) {
>>     if (str == null) {
>>         return appendNull();
>>     }
>>     int len = str.length();
>>     ensureCapacityInternal(count + len);
>>     putStringAt(count, str);             // couldn't it be putStringAt(count, str, 0, len);
>>     count += len;
>>     return this;
>> }
>> 
>> Doing this here and in other places allows  to rid `private void putStringAt(int index, String str)` completely and reduce one nested method call, right?
>
> I think you've got the wrong idea: We _want_ to use `putStringAt(int, String)` now since it can call into `String.getBytes(String, int, byte)`, which has a simpler and more efficient implementation than `String.getBytes(String, int, int, byte, int)`, since it avoids a couple of `<< coder` operations. This makes up for most of the improvement between my initial and the current version of this patch. 
> 
> (There's also no nested delegation from `putStringAt(int, String)` to `putStringAt(int, String, int, int)` in my proposed patch.)

You are right, I've applied your patch locally incompletely and misunderstood it, my bad :)

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

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


More information about the core-libs-dev mailing list