mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8156071: List.of: reduce array copying during creation
Reviewed-by: psandoz, redestad
This commit is contained in:
parent
ea27a54bf0
commit
88d75c9ad5
6 changed files with 203 additions and 18 deletions
|
@ -56,6 +56,8 @@ import java.util.function.ToDoubleFunction;
|
|||
import java.util.function.ToIntFunction;
|
||||
import java.util.function.ToLongFunction;
|
||||
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Implementations of {@link Collector} that implement various useful reduction
|
||||
* operations, such as accumulating elements into collections, summarizing
|
||||
|
@ -296,7 +298,8 @@ public final class Collectors {
|
|||
Collector<T, ?, List<T>> toUnmodifiableList() {
|
||||
return new CollectorImpl<>((Supplier<List<T>>) ArrayList::new, List::add,
|
||||
(left, right) -> { left.addAll(right); return left; },
|
||||
list -> (List<T>)List.of(list.toArray()),
|
||||
list -> (List<T>)SharedSecrets.getJavaUtilCollectionAccess()
|
||||
.listFromTrustedArray(list.toArray()),
|
||||
CH_NOID);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue