On Sat, 3 Aug 2024 00:14:20 GMT, Michael Strauß <mstra...@openjdk.org> wrote:

>> modules/javafx.graphics/src/main/java/com/sun/javafx/util/Utils.java line 
>> 197:
>> 
>>> 195:         if (secondList.isEmpty()) {
>>> 196:             return firstList.isEmpty() ? firstList : secondList;
>>> 197:         }
>> 
>> This logic looks odd.  If the second list is empty, we return the first list 
>> **if** it is empty (and so empty is returned), otherwise the second list 
>> (which is also empty).  So, this is equivalent?
>> Suggestion:
>> 
>>         if (secondList.isEmpty()) {
>>             return List.of();  // suggested here, as the two input lists are 
>> not guaranteed to be immutable
>>         }
>
> The point of this excercise is to preferrably return existing instances, even 
> when they are empty. `Border` and `Background` can contain quite a lot of 
> objects, and often only one component is changed in a transition, while all 
> of the rest is left unchanged. We want to elide the allocation of new objects 
> if possible during transitions, which is why most classes check whether the 
> result of an interpolation happens to be the same instance as either the 
> start value or the end value.

But you are checking this with `equals` I hope?  `List.of()` is a constant, it 
doesn't allocate anything.

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1522#discussion_r1702670114

Reply via email to