[OpenJDK 2D-Dev] RFR: 8269130: Replace usages of Collection.toArray() with Collection.toArray(T[]) to avoid redundant array copying

Andrey Turbanov github.com+741251+turbanoff at openjdk.java.net
Mon Aug 9 07:22:32 UTC 2021


On Mon, 26 Jul 2021 19:15:55 GMT, Brett Okken <github.com+2996845+bokken 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]);
> 
> 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)?

May be yes, may be not. I like `0`-sized array approach more.
1. It looks clearer and easier to read
2. It should be faster than original code anyway

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

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


More information about the 2d-dev mailing list