RFR: 6323374: (coll) Optimize Collections.unmodifiable* and synchronized* [v5]

Joe Darcy darcy at openjdk.java.net
Wed Mar 3 23:32:41 UTC 2021


On Fri, 26 Feb 2021 20:15:19 GMT, Ian Graves <igraves at openjdk.org> wrote:

>> Modify the `unmodifiable*` methods in `java.util.Collections` to be idempotent. That is, when given an immutable collection from `java.util.ImmutableCollections` or `java.util.Collections`, these methods will return the reference instead of creating a new immutable collection that wraps the existing one.
>
> Ian Graves has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Test refactoring. Adding implNote to modified methods

src/java.base/share/classes/java/util/Collections.java line 1168:

> 1166:      */
> 1167:     public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) {
> 1168:         if (s.getClass() == UnmodifiableSortedSet.class) {

Should a check like this also included "|| == UnmodifiableNavigableSet.class" or was there an explicit decision that the cost/benefit is not worthwhile, unlike in the case of unmodifiableList below?

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

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


More information about the core-libs-dev mailing list