On Thu, 18 Nov 2021 00:55:18 GMT, Nir Lisker <nlis...@openjdk.org> wrote:

>> This work improves the performance of `MultipleSelectionModel`  over large 
>> data sets by caching some values and avoiding unnecessary calls to 
>> `SelectedIndicesList#size`. It further improves the performance by reducing 
>> the number of iterations required to find the index of an element in the 
>> BitSet.
>> 
>> The work is based on [an abandoned 
>> patch](https://github.com/openjdk/jfx/pull/127) submitted by @yososs
>> 
>> There are currently 2 manual tests for this fix.
>
> modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/ReadOnlyUnbackedObservableList.java
>  line 119:
> 
>> 117:             Object obj = get(i);
>> 118:             if (o.equals(obj)) return i;
>> 119:         }
> 
> An alternative is
> 
> return IntStream.range(0, size())
>     .filter(i -> o.equals(get(i)))
>     .findFirst()
>     .orElse(-1);
> 
> I don't know if it helps.

the for-loop is certainly faster and would allocate less memory - i find the 
`for(int i = 0, max = size())`-style a bit odd

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

PR: https://git.openjdk.java.net/jfx/pull/673

Reply via email to