On Fri, 27 May 2022 19:52:30 GMT, Claes Redestad <redes...@openjdk.org> wrote:

>> In preparation of #8855 this PR refactors the conversions from `List` to 
>> array and array to `List`, reducing the number of conversions when calling 
>> `MethodHandles.dropArguments` in particular. This remove about ~5% of 
>> allocations on the `StringConcatFactoryBootstraps` microbenchmark.
> 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 5462:

> 5460:         Objects.requireNonNull(target);
> 5461:         Objects.requireNonNull(newTypes);
> 5462:         return dropArgumentsToMatch(target, skip, newTypes.toArray(new 
> Class<?>[0]).clone(), pos, false);

Do we really need to clone an array returned from `List.toArray()`? As far as I 
know from the JavaDoc of `List` if the passed array is not long enough to 
include all the items then the new array must be allocated. Here we always pass 
empty arrays, so the new ones are returned from `toArray()` method and we don't 
need `clone()`, right?


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

Reply via email to