This PR is an optimization for `Node.styleClass` and `Parent.stylesheets`. Instead of always initializing both properties with an empty list, we are creating (therefore allocating) the list on the first access instead. Similar to many other lazy properties.
Why? - `Parent.getStylesheets()` is very rarely used by developers and JavaFX code. So this list is very often completely unused and empty. Most developers usually only add stylesheets at the `Scene` - `Node.getStyleClass()` is usually not used (empty) for layout containers such as `Pane` or `Group`. A JavaFX App usually consists of a good amount of such containers So that our CSS code is not initializing both lists on access, I added related `NodeHelper` and `ParentHelper` methods to return `null` when both lists were not initialized and therefore used. Otherwise we return the list as before. This will save us some memory and allocation, which is both good for the memory consumption but also for `Node` / `Parent` creation (time). Added documentation and tests. Will do some measurements with some apps very soon and attach it here. --------- - [x] I confirm that I make this contribution in accordance with the [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). ------------- Commit messages: - 8386663: Stylesheet/StyleClass list should be lazily initialized Changes: https://git.openjdk.org/jfx/pull/2191/files Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2191&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8386663 Stats: 286 lines in 8 files changed: 221 ins; 34 del; 31 mod Patch: https://git.openjdk.org/jfx/pull/2191.diff Fetch: git fetch https://git.openjdk.org/jfx.git pull/2191/head:pull/2191 PR: https://git.openjdk.org/jfx/pull/2191
