-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8362958: Unnecessary copying / sorting in Streams using Comparator.naturalOrder() #28226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
8362958: Unnecessary copying / sorting in Streams using Comparator.naturalOrder() #28226
Conversation
|
👋 Welcome back kilink! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
634bd4d to
c4fb5d0
Compare
|
@kilink Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information. |
Webrevs
|
Simplify comparison Co-authored-by: Viktor Klang <viktor.klang@oracle.com>
|
I wonder if it's not better to replace Comparator.naturalOrder() by null in the constructor of TreeSet, given that TreeSet does not provide a getter for it so the only way to get the comparator is using treeSet.spliterator().getComparator(). |
That wouldn't help with the |
If you switch from Comparator.naturalOrder()) to null, you have to do it in stream.sorted() too (and also List.sort(Comparator), Collections.sort(Comparator), Array.sort(Comparator), Collections.reverseOrder(Comparator) etc)
yes, comparing comparators with == is brittle anyway, but at least you can make it consistent for the JDK. |
When
Comparator.naturalOrder()was explicitly supplied to a collection such asTreeSet, or passed into thesortedmethod of a stream, the sorted characteristic was not preserved, causing unnecessary buffering and duplicate sorting.Example:
or
This PR updates
SortedOps.makeRefandStreamOpFlag.fromCharacteristicsto handle the above cases and avoid the unnecessary sort step.Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28226/head:pull/28226$ git checkout pull/28226Update a local copy of the PR:
$ git checkout pull/28226$ git pull https://git.openjdk.org/jdk.git pull/28226/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28226View PR using the GUI difftool:
$ git pr show -t 28226Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28226.diff
Using Webrev
Link to Webrev Comment