Skip to content

Commit

Permalink
Don't use ImmutableSet.of() for the keySet of ImmutableMap.of().
Browse files Browse the repository at this point in the history
The keySet of the empty map will still be a singleton (since the empty map is a singleton and it caches keySet), it'll just be a different singleton from ImmutableSet.of().  This ensures that the only implementation of ImmutableSet retained by usages of ImmutableMap are its own keySet implementations.

Effects on ImmutableMapProGuard ([]38966 bytes => 37886 bytes
37 classes => 36 classes
231 methods => 219 methods

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=147078624
  • Loading branch information
lowasser authored and cpovirk committed Feb 9, 2017
1 parent f267c4a commit aafccea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public ImmutableSet<K> keySet() {
}

ImmutableSet<K> createKeySet() {
return isEmpty() ? ImmutableSet.<K>of() : new ImmutableMapKeySet<K, V>(this);
return new ImmutableMapKeySet<K, V>(this);
}

UnmodifiableIterator<K> keyIterator() {
Expand Down

0 comments on commit aafccea

Please sign in to comment.