RFR: 8269130: Replace usages of Collection.toArray() with Collection.toArray(T[]) to avoid redundant array copying
Michael Bien
github.com+114367+mbien at openjdk.java.net
Mon Jul 26 11:30:21 UTC 2021
On Mon, 14 Jun 2021 17:00:29 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:
> 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[])`.
src/java.base/share/classes/java/security/Security.java line 656:
> 654: return null;
> 655:
> 656: return candidates.toArray(new Provider[0]);
`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)
-------------
PR: https://git.openjdk.java.net/jdk/pull/4487
More information about the security-dev
mailing list