RFR: 8283063: Optimize Observable{List/Set/Map}Wrapper.retainAll/removeAll

Michael Strauß mstrauss at openjdk.java.net
Sat Mar 12 05:02:14 UTC 2022


`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.

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

Commit messages:
 - Optimize removeAll/retainAll for Observable{List/Set/Map}Wrapper
 - Failing test

Changes: https://git.openjdk.java.net/jfx/pull/751/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jfx&pr=751&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8283063
  Stats: 293 lines in 6 files changed: 290 ins; 0 del; 3 mod
  Patch: https://git.openjdk.java.net/jfx/pull/751.diff
  Fetch: git fetch https://git.openjdk.java.net/jfx pull/751/head:pull/751

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


More information about the openjfx-dev mailing list