aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Michajlo Matijkiw <michajlo@google.com>2016-07-21 01:01:31 +0000
committerGravatar John Cater <jcater@google.com>2016-07-21 20:35:08 +0000
commit0eb4da7d8e4503a508b9c42bb9e4002ac178cbca (patch)
tree014750d25027541158db30bb494bb47f90e1e2ba /src/main/java/com/google
parent8770c4ead68956aebfdbb9af2d4a6440ce2a3021 (diff)
Remove Rule's dependence on a RawAttributeMapper instance
The things Rule needs it for aren't terribly complex. Instead inline functionality where sensible, and refactor into static methods where not. This reduces each Rule's memory footprint by 38%. -- MOS_MIGRATED_REVID=128011760
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java25
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/Rule.java14
2 files changed, 30 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
index 1d15ce8499..f37613fd04 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
@@ -19,7 +19,6 @@ import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.BuildType.SelectorList;
import com.google.devtools.build.lib.syntax.Type;
-
import javax.annotation.Nullable;
/**
@@ -164,10 +163,20 @@ public abstract class AbstractAttributeMapper implements AttributeMap {
}
@Override
- public <T> boolean isConfigurable(String attributeName, Type<T> type) {
+ public final <T> boolean isConfigurable(String attributeName, Type<T> type) {
return getSelectorList(attributeName, type) != null;
}
+ public static <T> boolean isConfigurable(Rule rule, String attributeName, Type<T> type) {
+ SelectorList<T> selectorMaybe = getSelectorList(
+ rule.getRuleClassObject(),
+ rule.getLabel(),
+ rule.getAttributeContainer(),
+ attributeName,
+ type);
+ return selectorMaybe != null;
+ }
+
/**
* Returns a {@link SelectorList} for the given attribute if the attribute is configurable
* for this rule, null otherwise.
@@ -178,8 +187,18 @@ public abstract class AbstractAttributeMapper implements AttributeMap {
* @throws IllegalArgumentException if the attribute is configurable but of the wrong type
*/
@Nullable
+ protected final <T> SelectorList<T> getSelectorList(String attributeName, Type<T> type) {
+ return getSelectorList(ruleClass, ruleLabel, attributes, attributeName, type);
+ }
+
+ @Nullable
@SuppressWarnings("unchecked")
- protected <T> SelectorList<T> getSelectorList(String attributeName, Type<T> type) {
+ protected static <T> SelectorList<T> getSelectorList(
+ RuleClass ruleClass,
+ Label ruleLabel,
+ AttributeContainer attributes,
+ String attributeName,
+ Type<T> type) {
Integer index = ruleClass.getAttributeIndex(attributeName);
if (index == null) {
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
index cd813c31f5..77cc19db9b 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
@@ -70,7 +70,6 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
private final RuleClass ruleClass;
private final AttributeContainer attributes;
- private final RawAttributeMapper attributeMap;
private RuleVisibility visibility;
@@ -89,7 +88,6 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
this.ruleClass = Preconditions.checkNotNull(ruleClass);
this.location = Preconditions.checkNotNull(location);
this.attributes = attributeContainer;
- this.attributeMap = new RawAttributeMapper(pkg, ruleClass, label, attributes);
this.containsErrors = false;
}
@@ -194,7 +192,7 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
*/
public boolean hasConfigurableAttributes() {
for (Attribute attribute : getAttributes()) {
- if (attributeMap.isConfigurable(attribute.getName(), attribute.getType())) {
+ if (AbstractAttributeMapper.isConfigurable(this, attribute.getName(), attribute.getType())) {
return true;
}
}
@@ -205,7 +203,10 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
* Returns true if the given attribute is configurable.
*/
public boolean isConfigurableAttribute(String attributeName) {
- return attributeMap.isConfigurable(attributeName, attributeMap.getAttributeType(attributeName));
+ Attribute attribute = ruleClass.getAttributeByNameMaybe(attributeName);
+ return attribute != null
+ ? AbstractAttributeMapper.isConfigurable(this, attributeName, attribute.getType())
+ : false;
}
/**
@@ -216,7 +217,7 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
*/
@Deprecated
public Attribute getAttributeDefinition(String attrName) {
- return attributeMap.getAttributeDefinition(attrName);
+ return ruleClass.getAttributeByNameMaybe(attrName);
}
/**
@@ -307,7 +308,7 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
* with the given name.
*/
public boolean isAttributeValueExplicitlySpecified(String attrName) {
- return attributeMap.isAttributeValueExplicitlySpecified(attrName);
+ return attributes.isAttributeValueExplicitlySpecified(attrName);
}
/**
@@ -469,6 +470,7 @@ public final class Rule implements Target, DependencyFilter.AttributeInfoProvide
private void populateImplicitOutputFiles(EventHandler eventHandler, Package.Builder pkgBuilder)
throws InterruptedException {
try {
+ RawAttributeMapper attributeMap = RawAttributeMapper.of(this);
for (String out : ruleClass.getImplicitOutputsFunction().getImplicitOutputs(attributeMap)) {
try {
addOutputFile(pkgBuilder.createLabel(out), eventHandler);