Skip to content

Make sorting in FilteredList and TwoPaneElementSelector stable - #4523

Open
deepika-u wants to merge 1 commit into
eclipse-platform:masterfrom
deepika-u:filtered_list_order
Open

deepika-u wants to merge 1 commit into
eclipse-platform:masterfrom
deepika-u:filtered_list_order

Conversation

@deepika-u

@deepika-u deepika-u commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary
TwoArrayQuickSorter was an unstable quicksort, so FilteredList and TwoPaneElementSelector could reorder entries that compare as equal. This PR replaces it with a stable merge sort. Equal entries now keep the order in which they were passed in.

Problem
In the JDT dialog that opens on Ctrl+Click on a key in a properties file, the "Details" list showed the matches of one file out of order:

Without the pr ->
image

With the pr ->
image

The cause is in org.eclipse.ui.dialogs:

  • FilteredList.setElements sorts the upper list by label. Entries with identical labels, such as KeyUser.java (3 matches), are folded into one row, but the unstable sort had already shuffled them.
  • TwoPaneElementSelector.updateLowerListWidget sorts the lower list again. The caller can pass setLowerListComparator((a, b) -> 0) to keep the existing order, but an unstable sort still swaps equal elements.

Change

  • Replace the quicksort in TwoArrayQuickSorter with a stable merge sort. The signature and visibility are unchanged, so there is no
    API change. The class name is kept to keep the change small.
  • Add TwoPaneElementSelectorOrderTest and register it in UIAutomatedSuite.

Design notes

  • The merge copies only its left run to a buffer (about 4 bytes per element) and is skipped for runs that are already in order.
  • It never throws for an inconsistent comparator, unlike Arrays.sort, which matters because setLowerListComparator() is public API.
  • A micro-benchmark on String keys showed about the same speed as the old quicksort, and faster for large inputs.
  • Fixing only the caller was rejected: it would have to parse the label text and would not fix the upper list.

Testing

  • Manual: Ctrl+Click on a key with three matches in one file. The Details list was 28, 29, 12 without this change and 12, 28, 29 with
    it.
  • TwoPaneElementSelectorOrderTest: ran as a JUnit Plug-in Test. It passes with this change, and testLowerListKeepsOrderOfFoldedElements fails without TwoArrayQuickSorter.java change.

@deepika-u

Copy link
Copy Markdown
Contributor Author

@merks : When you get some time, could you take a look at this please?

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

   867 files  ±0     867 suites  ±0   57m 58s ⏱️ + 3m 46s
 8 547 tests +2   8 307 ✅ +2  240 💤 ±0  0 ❌ ±0 
21 513 runs  +6  20 840 ✅ +6  673 💤 ±0  0 ❌ ±0 

Results for commit d05fe4b. ± Comparison against base commit ad7efa0.

♻️ This comment has been updated with latest results.

@deepika-u
deepika-u force-pushed the filtered_list_order branch 5 times, most recently from 0ac8aee to d5b8313 Compare November 3, 2026 05:53
@deepika-u

Copy link
Copy Markdown
Contributor Author

@merks
Since you might have so many notifications popping you - this might have got missed in the full list.
When you get some time, can you take a look at this please?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the stable-sorting change.

No open issues 🎉

What changed in this PR

This PR makes sorting stable in FilteredList and TwoPaneElementSelector, preserving input order for entries that compare as equal.

Changes:

  • Replace quicksort with a stable merge sort while retaining the existing class name and signatures.
  • Add UI tests for folded-entry ordering and default case-insensitive sorting.
  • Register the new tests in the automated dialog suite.
File Description
tests/​org.eclipse.ui.tests/​Eclipse UI Tests/​org/​eclipse/​ui/​tests/​dialogs/​UIAutomatedSuite.java Registers the new ordering tests.
tests/​org.eclipse.ui.tests/​Eclipse UI Tests/​org/​eclipse/​ui/​tests/​dialogs/​TwoPaneElementSelectorOrderTest.java Tests stable folded-entry ordering and default sorting.
bundles/​org.eclipse.ui.workbench/​eclipseui/​org/​eclipse/​ui/​dialogs/​TwoArrayQuickSorter.java Implements stable merge sorting of parallel key-value arrays.

Review effort: Balanced

@deepika-u
deepika-u force-pushed the filtered_list_order branch 2 times, most recently from 81a1460 to 60aa35a Compare November 10, 2026 05:40
@deepika-u

Copy link
Copy Markdown
Contributor Author

@merks
Copilot already recommended an approval, can you take a look at it once you get some time please? (This might not take much time - like other fixes since technically nothing has changed only order is updated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants