From a954fae3183ff68521dff650a405c505394a9917 Mon Sep 17 00:00:00 2001 From: Eric Fellheimer Date: Thu, 27 Aug 2015 19:37:52 +0000 Subject: Avoid repeated copies of RuleClass attributes. -- MOS_MIGRATED_REVID=101707604 --- .../com/google/devtools/build/lib/packages/RuleClass.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/packages') diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java index 3affb169cf..ee1fce3bb8 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java +++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java @@ -916,7 +916,7 @@ public final class RuleClass { * All attributes of this rule class (including inherited ones) ordered by * attributeIndex value. */ - private final Attribute[] attributes; + private final ImmutableList attributes; /** * The set of implicit outputs generated by a rule, expressed as a function @@ -1098,8 +1098,7 @@ public final class RuleClass { this.configuredTargetFunction = configuredTargetFunction; this.externalBindingsFunction = externalBindingsFunction; this.ruleDefinitionEnvironment = ruleDefinitionEnvironment; - // Do not make a defensive copy as builder does that already - this.attributes = attributes; + this.attributes = ImmutableList.copyOf(attributes); this.workspaceOnly = workspaceOnly; this.outputsDefaultExecutable = outputsDefaultExecutable; this.requiredConfigurationFragments = ImmutableSet.copyOf(allowedConfigurationFragments); @@ -1186,14 +1185,14 @@ public final class RuleClass { * not in range. */ Attribute getAttribute(int attrIndex) { - return attributes[attrIndex]; + return attributes.get(attrIndex); } /** * Returns the attribute whose name is 'attrName'; fails if not found. */ public Attribute getAttributeByName(String attrName) { - return attributes[getAttributeIndex(attrName)]; + return attributes.get(getAttributeIndex(attrName)); } /** @@ -1202,7 +1201,7 @@ public final class RuleClass { */ Attribute getAttributeByNameMaybe(String attrName) { Integer i = getAttributeIndex(attrName); - return i == null ? null : attributes[i]; + return i == null ? null : attributes.get(i); } /** @@ -1217,7 +1216,7 @@ public final class RuleClass { * rule, ordered by increasing index. */ public List getAttributes() { - return ImmutableList.copyOf(attributes); + return attributes; } public PredicateWithMessage getValidityPredicate() { -- cgit v1.2.3