diff options
author | Michajlo Matijkiw <michajlo@google.com> | 2015-12-11 19:12:06 +0000 |
---|---|---|
committer | David Chen <dzc@google.com> | 2015-12-13 18:27:37 +0000 |
commit | 1812967ba20266cae559bf117f0efc8e32d43fcf (patch) | |
tree | 85f91353ae3f3acccc10a9197be6159389ad9923 /src/main/java/com/google/devtools/build/lib/packages | |
parent | 1373e6681e4b54f271aa3a2c762a915b462d0da7 (diff) |
Move Selector#defaultConditionLabel to static final var
Prevents overhead of extra Labels in builds with lots of selectors
--
MOS_MIGRATED_REVID=110011063
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/BuildType.java | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java index be66fc88ed..831b279666 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java +++ b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java @@ -436,34 +436,28 @@ public final class BuildType { * objects of the attribute's native Type. */ public static final class Selector<T> { + /** Value to use when none of an attribute's selection criteria match. */ + @VisibleForTesting + public static final String DEFAULT_CONDITION_KEY = "//conditions:default"; + + private static final Label DEFAULT_CONDITION_LABEL = + Label.parseAbsoluteUnchecked(DEFAULT_CONDITION_KEY); + private final Type<T> originalType; private final Map<Label, T> map; - private final Label defaultConditionLabel; private final boolean hasDefaultCondition; - /** - * Value to use when none of an attribute's selection criteria match. - */ - @VisibleForTesting - public static final String DEFAULT_CONDITION_KEY = "//conditions:default"; - @VisibleForTesting Selector(Object x, String what, @Nullable Label context, Type<T> originalType) throws ConversionException { Preconditions.checkState(x instanceof Map<?, ?>); - try { - defaultConditionLabel = Label.parseAbsolute(DEFAULT_CONDITION_KEY); - } catch (LabelSyntaxException e) { - throw new IllegalStateException(DEFAULT_CONDITION_KEY + " is not a valid label"); - } - this.originalType = originalType; Map<Label, T> result = Maps.newLinkedHashMap(); boolean foundDefaultCondition = false; for (Entry<?, ?> entry : ((Map<?, ?>) x).entrySet()) { Label key = LABEL.convert(entry.getKey(), what, context); - if (key.equals(defaultConditionLabel)) { + if (key.equals(DEFAULT_CONDITION_LABEL)) { foundDefaultCondition = true; } result.put(key, originalType.convert(entry.getValue(), what, context)); @@ -483,7 +477,7 @@ public final class BuildType { * Returns the value to use when none of the attribute's selection keys match. */ public T getDefault() { - return map.get(defaultConditionLabel); + return map.get(DEFAULT_CONDITION_LABEL); } /** @@ -506,7 +500,7 @@ public final class BuildType { * map to actual targets. */ public static boolean isReservedLabel(Label label) { - return label.toString().equals(DEFAULT_CONDITION_KEY); + return DEFAULT_CONDITION_LABEL.equals(label); } } |