Skip to content

Commit

Permalink
Switch ImmutableSortedMap over to using AbstractMap.SimpleImmutableEn…
Browse files Browse the repository at this point in the history
…try instead of ImmutableMapEntry.

Effects on ImmutableSortedMapProGuard ([]
62724 bytes => 60598 bytes
55 classes => 53 classes
444 methods => 432 methods

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148390060
  • Loading branch information
lowasser authored and cpovirk committed Feb 24, 2017
1 parent 327440e commit 01d67d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
20 changes: 11 additions & 9 deletions guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.errorprone.annotations.concurrent.LazyInit;
import com.google.j2objc.annotations.WeakOuter;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -164,14 +165,15 @@ public static <K, V> ImmutableMap<K, V> of(
// looking for of() with > 5 entries? Use the builder instead.

/**
* Verifies that {@code key} and {@code value} are non-null, and returns a new
* immutable entry with those values.
* Verifies that {@code key} and {@code value} are non-null, and returns a new immutable entry
* with those values.
*
* <p>A call to {@link Map.Entry#setValue} on the returned entry will always
* throw {@link UnsupportedOperationException}.
* <p>A call to {@link Map.Entry#setValue} on the returned entry will always throw {@link
* UnsupportedOperationException}.
*/
static <K, V> ImmutableMapEntry<K, V> entryOf(K key, V value) {
return new ImmutableMapEntry<K, V>(key, value);
static <K, V> Entry<K, V> entryOf(K key, V value) {
checkEntryNotNull(key, value);
return new AbstractMap.SimpleImmutableEntry<K, V>(key, value);
}

/**
Expand Down Expand Up @@ -212,7 +214,7 @@ static void checkNoConflict(
*/
public static class Builder<K, V> {
Comparator<? super V> valueComparator;
ImmutableMapEntry<K, V>[] entries;
Entry<K, V>[] entries;
int size;
boolean entriesUsed;

Expand All @@ -226,7 +228,7 @@ public Builder() {

@SuppressWarnings("unchecked")
Builder(int initialCapacity) {
this.entries = new ImmutableMapEntry[initialCapacity];
this.entries = new Entry[initialCapacity];
this.size = 0;
this.entriesUsed = false;
}
Expand All @@ -247,7 +249,7 @@ private void ensureCapacity(int minCapacity) {
@CanIgnoreReturnValue
public Builder<K, V> put(K key, V value) {
ensureCapacity(size + 1);
ImmutableMapEntry<K, V> entry = entryOf(key, value);
Entry<K, V> entry = entryOf(key, value);
// don't inline this: we want to fail atomically if key or value is null
entries[size++] = entry;
return this;
Expand Down
7 changes: 4 additions & 3 deletions guava/src/com/google/common/collect/ImmutableSortedMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import com.google.common.annotations.GwtCompatible;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.j2objc.annotations.WeakOuter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.Spliterator;
Expand Down Expand Up @@ -155,7 +155,7 @@ private static <K, V> ImmutableSortedMap<K, V> of(Comparator<? super K> comparat
}

private static <K extends Comparable<? super K>, V> ImmutableSortedMap<K, V> ofEntries(
ImmutableMapEntry<K, V>... entries) {
Entry<K, V>... entries) {
return fromEntries(Ordering.natural(), false, entries, entries.length);
}

Expand Down Expand Up @@ -640,7 +640,8 @@ ImmutableList<Entry<K, V>> createAsList() {
return new ImmutableAsList<Entry<K, V>>() {
@Override
public Entry<K, V> get(int index) {
return Maps.immutableEntry(keySet.asList().get(index), valueList.get(index));
return new AbstractMap.SimpleImmutableEntry<K, V>(
keySet.asList().get(index), valueList.get(index));
}

@Override
Expand Down

0 comments on commit 01d67d3

Please sign in to comment.