On Tue, 17 Jan 2023 08:22:28 GMT, Sergey Tsypanov <stsypa...@openjdk.org> wrote:

> - `MethodType.ptypes()` can be used instead of `MethodType.parameterList()` 
> when we don't need a copy
> - comparison of two lists can be done without `Stream.reduce()`

src/java.base/share/classes/java/lang/invoke/MethodHandles.java line 6754:

> 6752:                         filter(t -> t.parameterCount() > skipSize).
> 6753:                         map(MethodType::ptypes).
> 6754:                         reduce((p, q) -> p.length >= q.length ? p : 
> q).orElse(EMPTY);

Could avoid the need to introduce `EMPTY` if you make the stream expression 
return the longest list directly:

                reduce((p, q) -> {
                    var longest = (p.size() >= q.size()) ? p : q;
                    return List.of(Arrays.copyOfRange(longest, skipSize, 
longest.size()); // checking isEmpty() is redundant here since we filter on 
`t.parameterCount() > skipSize`
                }).orElse(List.of());

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

PR: https://git.openjdk.org/jdk/pull/12025

Reply via email to