On Tue, 15 Jun 2021 12:06:43 GMT, Michael Bien <github.com+114367+mb...@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) Actually it's not _the fast path_ - see https://shipilev.net/blog/2016/arrays-wisdom-ancients/ ------------- PR: https://git.openjdk.java.net/jdk/pull/4487