Skip to content

Commit 75f13f7

Browse files
eamonnmcmanusGoogle Java Core Libraries
authored andcommitted
Improve variable name and explanatory comments.
RELNOTES=n/a PiperOrigin-RevId: 416627986
1 parent 87d550f commit 75f13f7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

guava/src/com/google/common/collect/RegularImmutableMap.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,31 @@ private static <K, V> ImmutableMap<K, V> fromEntryArrayCheckingBucketOverflow(
128128
checkEntryNotNull(key, value);
129129
int tableIndex = Hashing.smear(key.hashCode()) & mask;
130130
ImmutableMapEntry<K, V> keyBucketHead = table[tableIndex];
131-
ImmutableMapEntry<K, V> newEntry =
131+
ImmutableMapEntry<K, V> effectiveEntry =
132132
checkNoConflictInKeyBucket(key, value, keyBucketHead, throwIfDuplicateKeys);
133-
if (newEntry == null) {
133+
if (effectiveEntry == null) {
134134
// prepend, not append, so the entries can be immutable
135-
newEntry =
135+
effectiveEntry =
136136
(keyBucketHead == null)
137137
? makeImmutable(entry, key, value)
138138
: new NonTerminalImmutableMapEntry<K, V>(key, value, keyBucketHead);
139-
table[tableIndex] = newEntry;
139+
table[tableIndex] = effectiveEntry;
140140
} else {
141+
// We already saw this key, and the first value we saw (going backwards) is the one we are
142+
// keeping. So we won't touch table[], but we do still want to add the existing entry that
143+
// we found to entries[] so that we will see this key in the right place when iterating.
141144
if (duplicates == null) {
142145
duplicates = new IdentityHashMap<>();
143146
}
144-
duplicates.put(newEntry, true);
147+
duplicates.put(effectiveEntry, true);
145148
dupCount++;
146149
// Make sure we are not overwriting the original entries array, in case we later do
147150
// buildOrThrow(). We would want an exception to include two values for the duplicate key.
148151
if (entries == entryArray) {
149152
entries = entries.clone();
150153
}
151154
}
152-
entries[entryIndex] = newEntry;
155+
entries[entryIndex] = effectiveEntry;
153156
}
154157
if (duplicates != null) {
155158
// Explicit type parameters needed here to avoid a problem with nullness inference.

0 commit comments

Comments
 (0)