|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
59 | 59 | import java.util.ArrayList;
|
60 | 60 | import java.util.Arrays;
|
61 | 61 | import java.util.BitSet;
|
| 62 | +import java.util.Comparator; |
62 | 63 | import java.util.Iterator;
|
63 | 64 | import java.util.List;
|
64 | 65 | import java.util.Objects;
|
@@ -6744,25 +6745,19 @@ private static void loopChecks1a(int i, MethodHandle in, MethodHandle st) {
|
6744 | 6745 | }
|
6745 | 6746 |
|
6746 | 6747 | private static List<Class<?>> longestParameterList(Stream<MethodHandle> mhs, int skipSize) {
|
6747 |
| - final List<Class<?>> empty = List.of(); |
6748 |
| - final List<Class<?>> longest = mhs.filter(Objects::nonNull). |
| 6748 | + return mhs.filter(Objects::nonNull) |
6749 | 6749 | // take only those that can contribute to a common suffix because they are longer than the prefix
|
6750 |
| - map(MethodHandle::type). |
6751 |
| - filter(t -> t.parameterCount() > skipSize). |
6752 |
| - map(MethodType::parameterList). |
6753 |
| - reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty); |
6754 |
| - return longest.isEmpty() ? empty : longest.subList(skipSize, longest.size()); |
6755 |
| - } |
6756 |
| - |
6757 |
| - private static List<Class<?>> longestParameterList(List<List<Class<?>>> lists) { |
6758 |
| - final List<Class<?>> empty = List.of(); |
6759 |
| - return lists.stream().reduce((p, q) -> p.size() >= q.size() ? p : q).orElse(empty); |
| 6750 | + .map(MethodHandle::type) |
| 6751 | + .filter(t -> t.parameterCount() > skipSize) |
| 6752 | + .max(Comparator.comparingInt(MethodType::parameterCount)) |
| 6753 | + .map(methodType -> List.of(Arrays.copyOfRange(methodType.ptypes(), skipSize, methodType.parameterCount()))) |
| 6754 | + .orElse(List.of()); |
6760 | 6755 | }
|
6761 | 6756 |
|
6762 | 6757 | private static List<Class<?>> buildCommonSuffix(List<MethodHandle> init, List<MethodHandle> step, List<MethodHandle> pred, List<MethodHandle> fini, int cpSize) {
|
6763 | 6758 | final List<Class<?>> longest1 = longestParameterList(Stream.of(step, pred, fini).flatMap(List::stream), cpSize);
|
6764 | 6759 | final List<Class<?>> longest2 = longestParameterList(init.stream(), 0);
|
6765 |
| - return longestParameterList(List.of(longest1, longest2)); |
| 6760 | + return longest1.size() >= longest2.size() ? longest1 : longest2; |
6766 | 6761 | }
|
6767 | 6762 |
|
6768 | 6763 | private static void loopChecks1b(List<MethodHandle> init, List<Class<?>> commonSuffix) {
|
|
0 commit comments