RFR: 8300237: Minor improvements in MethodHandles

Claes Redestad redestad at openjdk.org
Tue Jan 17 09:55:12 UTC 2023


On Tue, 17 Jan 2023 08:22:28 GMT, Sergey Tsypanov <stsypanov at 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


More information about the core-libs-dev mailing list