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
8269130: Replace usages of Collection.toArray() with Collection.toArray(T[]) to avoid redundant array copying #4487
Conversation
…o avoid redundant array copying
👋 Welcome back turbanoff! A progress list of the required criteria for merging this PR into |
@turbanoff The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
…o avoid redundant array copying update copyright.
src/java.desktop/share/classes/sun/java2d/SunGraphicsEnvironment.java
Outdated
Show resolved
Hide resolved
…o avoid redundant array copying fix incorrect conversion: previously the code returns values
} | ||
|
||
return result; | ||
return candidates.toArray(new Provider[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
candidates.toArray(new Provider[candidates.size()]);
would use the fast path of the toArray() implementation. Performance probably doesn't matter much in a lot of this cases, but since its only a few characters more, its still worth considering IMO.
The only places I would leave this out are on the HashTable and on the Vector collections in this PR, since calling one synchronized method is not the same as calling two - concurrency wise.
(i am no reviewer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it's not the fast path - see https://shipilev.net/blog/2016/arrays-wisdom-ancients/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I am sorry my mistake - I actually now remember reading the article. (It would be interesting to rerun the benchmark on modern JDKs since I would expect the gap to be smaller now)
Please disregard my suggestion.
@turbanoff I've filed a ticket for this: https://bugs.openjdk.java.net/browse/JDK-8269130. Also I think you can integrate #4482 |
@turbanoff This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes to the security classes look good.
@turbanoff This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 714 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@seanjmullan, @mrserb) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
} | ||
|
||
return result; | ||
return candidates.toArray(new Provider[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this called often enough to warrant creating a constant of new Provider[0]
(benefits of this covered in the Wisdom of the Ancients blog linked)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be yes, may be not. I like 0
-sized array approach more.
- It looks clearer and easier to read
- It should be faster than original code anyway
Object[] tmpArray = tmp.toArray(); | ||
InstanceKlass[] searchResult = new InstanceKlass[tmpArray.length]; | ||
System.arraycopy(tmpArray, 0, searchResult, 0, tmpArray.length); | ||
InstanceKlass[] searchResult = tmp.toArray(new InstanceKlass[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it too far outside the scope of these changes to make tmp
an ArrayList
rather than a Vector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create separate PRs to migrate Vector usages to ArrayList.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in the desktop module looks fine.
/integrate |
@turbanoff |
/sponsor |
Going to push as commit 35b399a.
Your commit was automatically rebased without conflicts. |
@jayathirthrao @turbanoff Pushed as commit 35b399a. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
I found few places, where code initially perform
Object[] Colleciton.toArray()
call and then manually copy array into another array with required type.This PR cleanups such places to more shorter call
T[] Collection.toArray(T[])
.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4487/head:pull/4487
$ git checkout pull/4487
Update a local copy of the PR:
$ git checkout pull/4487
$ git pull https://git.openjdk.java.net/jdk pull/4487/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4487
View PR using the GUI difftool:
$ git pr show -t 4487
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4487.diff