Fixes [8202066](https://bugs.openjdk.org/browse/JDK-8202066)

`selectRows(int, int)` calls `clearSelection(int)` in a loop which is slow. 
There are two cases to consider: `minRow == maxRow` and `minRow < maxRow`. 

In both cases, all indices such that `selectedIndex < minRow || selectedIndex > 
maxRow` are cleared. `clearSelection(int)` clears the associated bit and clears 
the focus and selected index if operation causes the selected indices to be 
empty. 

**minRow == maxRow**

`select(int)` updates the focus and selected index if the input argument is not 
already selected. Otherwise, it is a no-up. Therefore, clearing all the 
selected indices with `clearSelection(int)` and calling `select(minRow)` is 
equivalent to `clearAndSelect(minRow)`. 

**minRow < maxRow**

`selectRange(int, int)` resolves to `selectIndices(int, int...)`, which updates 
the focus and selected index to the last valid index, regardless if that index 
was already selected. Therefore, the focus and selected index prior to 
`selectRange` is irrelevant. 


Results are encouraging:

[StringPlayground3.java](https://github.com/user-attachments/files/26034143/StringPlayground3.java)

Mainline:

Starting Benchmark with 5500 elements!
Robot finished in: 85ms
UI Unfroze after: 33108ms
Total Operation: 33193ms

With change:

Starting Benchmark with 5500 elements!
Robot finished in: 87ms
UI Unfroze after: 1ms
Total Operation: 88ms

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

Commit messages:
 - use clearAndSelect for edge case
 - replace clearSelection(int) loop with clearSelection()

Changes: https://git.openjdk.org/jfx/pull/2109/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2109&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8202066
  Stats: 13 lines in 1 file changed: 1 ins; 11 del; 1 mod
  Patch: https://git.openjdk.org/jfx/pull/2109.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2109/head:pull/2109

PR: https://git.openjdk.org/jfx/pull/2109

Reply via email to