RFR: 8283063: Optimize Observable{List/Set/Map}Wrapper.retainAll/removeAll
Marius Hanl
mhanl at openjdk.org
Thu Mar 30 10:48:32 UTC 2023
On Sun, 3 Jul 2022 23:25:09 GMT, Nir Lisker <nlisker at openjdk.org> wrote:
>> `Observable{List/Set/Map}Wrapper.retainAll/removeAll` can be optimized for some edge cases.
>>
>> 1. `removeAll(c)`:
>> This is a no-op if 'c' is empty.
>> For `ObservableListWrapper`, returning early skips an object allocation. For `ObservableSetWrapper` and `ObservableMapWrapper`, returning early prevents an enumeration of the entire collection.
>>
>> 2. `retainAll(c)`:
>> This is a no-op if the backing collection is empty, or equivalent to `clear()` if `c` is empty.
>>
>> I've added some tests to verify the optimized behavior for each of the three classes.
>
> modules/javafx.base/src/main/java/com/sun/javafx/collections/ObservableSetWrapper.java line 359:
>
>> 357:
>> 358: return false;
>> 359: }
>
> This is good, but if `!c.isEmpty()` then we can optimize too, I think: if `backingSet.isEmpty()`, then removing/retaining all will also return `false`. Then again, the iterator will return quickly, so it might not do much.
>
> If you take this path, I think that doing these optimizations in the `removeAll` and `retainAll` before calling this method will be clearer, similarly to how it's done in the `List` case.
>
> Same comment for the `Map` wrapper.
`+ 1` for this. Otherwise the changes look good to me.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/751#discussion_r1153074947
More information about the openjfx-dev
mailing list