aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/collect
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-02-23 12:47:02 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-23 12:48:47 -0800
commit6966a2e1fa3eb4eca71a10fe47661128284e8e4f (patch)
tree9b8e0e37de3b34add3d07fc6e510d4bcc0a690b7 /src/main/java/com/google/devtools/build/lib/collect
parent9f7eb09e53ed7720a5e0b038df67263e44c28101 (diff)
Better @AutoCodec for TransitiveInfoProviderMapImpl: avoid having to serialize offset table at the cost of some overhead reconstructing the table. Also fewer code changes, although there is a serialization-only method added as a hack.
PiperOrigin-RevId: 186808832
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/collect')
-rw-r--r--src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java b/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java
index 42a7af8723..65bb4a8883 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java
+++ b/src/main/java/com/google/devtools/build/lib/collect/ImmutableSharedKeyMap.java
@@ -42,16 +42,11 @@ import javax.annotation.concurrent.Immutable;
public class ImmutableSharedKeyMap<K, V> extends CompactImmutableMap<K, V> {
private static final Interner<OffsetTable> offsetTables = BlazeInterners.newWeakInterner();
+ private final OffsetTable<K> offsetTable;
// Visible only for serialization.
- protected final OffsetTable<K> offsetTable;
protected final Object[] values;
- /**
- * Table storing {@code keys} compactly as an array, with an index lookup map for speed.
- *
- * <p>Only externally visible for serialization purposes.
- */
- public static final class OffsetTable<K> {
+ private static final class OffsetTable<K> {
private final Object[] keys;
// Keep a map around to speed up get lookups for larger maps.
// We make this value lazy to avoid computing for values that end up being thrown away
@@ -104,14 +99,14 @@ public class ImmutableSharedKeyMap<K, V> extends CompactImmutableMap<K, V> {
}
}
- protected ImmutableSharedKeyMap(OffsetTable<K> offsetTable, Object[] values) {
- Preconditions.checkArgument(offsetTable.keys.length == values.length);
- this.offsetTable = offsetTable;
+ protected ImmutableSharedKeyMap(Object[] keys, Object[] values) {
+ Preconditions.checkArgument(keys.length == values.length);
this.values = values;
+ this.offsetTable = createOffsetTable(keys);
}
@SuppressWarnings("unchecked")
- protected static <K> OffsetTable<K> createOffsetTable(Object[] keys) {
+ private static <K> OffsetTable<K> createOffsetTable(Object[] keys) {
OffsetTable<K> offsetTable = new OffsetTable<>(keys);
OffsetTable<K> internedTable = (OffsetTable<K>) offsetTables.intern(offsetTable);
internedTable.initIndexMap();
@@ -142,6 +137,12 @@ public class ImmutableSharedKeyMap<K, V> extends CompactImmutableMap<K, V> {
return (V) values[index];
}
+ /** Do not use! Present only for serialization. (Annotated as @Deprecated just to prevent use.) */
+ @Deprecated
+ public Object[] getKeys() {
+ return offsetTable.keys;
+ }
+
@Override
@SuppressWarnings("ReferenceEquality")
public boolean equals(Object o) {
@@ -187,7 +188,7 @@ public class ImmutableSharedKeyMap<K, V> extends CompactImmutableMap<K, V> {
keys[i] = entries.get(entryIndex++);
values[i] = entries.get(entryIndex++);
}
- return new ImmutableSharedKeyMap<>(createOffsetTable(keys), values);
+ return new ImmutableSharedKeyMap<>(keys, values);
}
}
}