Skip iteration in visitLabels if the contained type does not need to visit labels.
This only accounts for ~0.1% analysis cpu on a typical build, but it was easy enough to just add this handling.
RELNOTES: None.
@@ -35,6 +35,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.RandomAccess;
import java.util.Set;
import java.util.logging.Level;
import javax.annotation.Nullable;
@@ -467,11 +468,13 @@ public abstract class Type<T> {
@Override
public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
+ if (labelClass != LabelClass.NONE) {
for (Map.Entry<KeyT, ValueT> entry : cast(value).entrySet()) {
keyType.visitLabels(visitor, entry.getKey(), context);
valueType.visitLabels(visitor, entry.getValue(), context);
}
}
+ }
public static <KEY, VALUE> DictType<KEY, VALUE> create(
Type<KEY> keyType, Type<VALUE> valueType) {
@@ -585,9 +588,13 @@ public abstract class Type<T> {
@Override
public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
+ if (elemType.getLabelClass() == LabelClass.NONE) {
+ return;
+ }
+
List<ElemT> elems = cast(value);
// Hot code path. Optimize for lists with O(1) access to avoid iterator garbage.
- if (elems instanceof ImmutableList || elems instanceof ArrayList) {
+ if (elems instanceof RandomAccess) {
for (int i = 0; i < elems.size(); i++) {
elemType.visitLabels(visitor, elems.get(i), context);
}
