RFR: 8287442: Reduce list to array conversions in java.lang.invoke.MethodHandles [v2]

Jorn Vernee jvernee at openjdk.java.net
Fri Jun 3 15:53:45 UTC 2022


On Fri, 3 Jun 2022 15:09:24 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Claes Redestad has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Review comments, eagerly convert sooner in tryFinally
>
> src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 5266:
> 
>> 5264:      */
>> 5265:     public static MethodHandle dropArguments(MethodHandle target, int pos, List<Class<?>> valueTypes) {
>> 5266:         return dropArguments(target, pos, valueTypes.toArray(new Class<?>[0]), false);
> 
> A bit unfortunate that we can't trust this `toArray` to do a copy. I was going to suggest Stream, but it has the same issue (someone might have a custom stream implementation).
> 
> I do think a manual copy of the array is possible by having a loop though:
> Suggestion:
> 
>         Class<?>[] ptypes = new Class<?>[valueTypes.size()];
>         for (int i = 0; i < ptypes.length; i++) {
>             ptypes[i] = valueTypes.get(i);
>         }
>         return dropArguments(target, pos, ptypes, false);
> 
> 
> (or, maybe extract such a loop to a helper method for clarity).

The same could be done for the public `dropArgumentsToMatch` I think.

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

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


More information about the core-libs-dev mailing list