RFR: 8273100: Improve AbstractStringBuilder.append(String) when using CompactStrings [v3]
Claes Redestad
redestad at openjdk.java.net
Mon Aug 30 14:09:31 UTC 2021
On Mon, 30 Aug 2021 13:35:23 GMT, Сергей Цыпанов <github.com+10835776+stsypanov at openjdk.org> wrote:
>> Claes Redestad has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Simplify and call getBytes(String, int, byte) when possible
>
> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1714:
>
>> 1712:
>> 1713: private void inflateIfNeededFor(String input) {
>> 1714: if (COMPACT_STRINGS && (coder != input.coder())) {
>
> I'm not completely sure whether it's a good idea in terms of maintainability, but I think this can be simplified a bit more. Currently in both `String` and `ASB` we have implementations of `coder()` very much alike:
>
> // ASB
> final byte getCoder() {
> return COMPACT_STRINGS ? coder : UTF16;
> }
>
> //String
> byte getCoder() {
> return COMPACT_STRINGS ? coder : UTF16;
> }
>
> Here we have this condition
>
> if (COMPACT_STRINGS && (coder != input.getCoder())) {}
>
> where the right operand of `&&` is evaluated only when `COMPACT_STRINGS` is `true` and hence it always returns the value of `coder` field. This means we can reference it directly as
>
> if (COMPACT_STRINGS && (coder != input.coder)) {}
I'm not sure if this'd give us enough to motivate the refactor, especially since we'd have to widen the visibility of `String.coder`. Maybe startup could be helped a little. Either way it feels out of scope for this change, don't you think?
-------------
PR: https://git.openjdk.java.net/jdk/pull/5291
More information about the core-libs-dev
mailing list