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:22 UTC 2021


On Tue, 15 Jun 2021 12:34:50 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:

>> 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)
>
> Actually it's not _the fast path_ - see https://shipilev.net/blog/2016/arrays-wisdom-ancients/

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.

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

PR: https://git.openjdk.java.net/jdk/pull/4487



More information about the security-dev mailing list