On Mon, 30 Aug 2021 14:04:27 GMT, Claes Redestad <[email protected]> wrote:

>> 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?

Agree

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

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

Reply via email to