aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-08-25 18:29:43 +0000
committerGravatar John Cater <jcater@google.com>2016-08-25 20:21:30 +0000
commit8ebfb43117a6d6a2597e0b54ebfbddf93922b98d (patch)
tree60c2ca4b69d0a9e0c9931b80ae5dfa6ba7370176 /src/test/java
parenta6595116da5fb80554496cd69e4ab74b93c7b1e4 (diff)
Some optimizations in Type#flatten (used under the covers by AggregatingAttributeMapper#visitLabels):
-Rename Type#flatten to Type#extractLabels. -Change the return type of Type#extractLabels from Collection to Iterable. This way we don't need to create and concatenate large lists. -Add an internal-only Type#containsLabels so this way ListType and DictType can have efficient implementations of Type#extractLabels. Note that AggregatingAttributeMapper#visitLabels is called multiple times on the same in several different places during the lifetime of a non-incremental Blaze invocation (e.g. during Package loading, during transitive target visitation, etc) -- MOS_MIGRATED_REVID=131311698
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java22
2 files changed, 14 insertions, 13 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
index 089430dfdf..dfd4f28cef 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/BuildTypeTest.java
@@ -66,7 +66,7 @@ public class BuildTypeTest {
/* symlinkBehavior */ null,
/* stripPrefix */ null);
assertEquals(input, BuildType.FILESET_ENTRY.convert(input, null, currentRule));
- assertThat(BuildType.FILESET_ENTRY.flatten(input)).containsExactly(entryLabel);
+ assertThat(BuildType.FILESET_ENTRY.extractLabels(input)).containsExactly(entryLabel);
}
@Test
@@ -90,7 +90,8 @@ public class BuildTypeTest {
/* symlinkBehavior */ null,
/* stripPrefix */ null));
assertEquals(input, BuildType.FILESET_ENTRY_LIST.convert(input, null, currentRule));
- assertThat(BuildType.FILESET_ENTRY_LIST.flatten(input)).containsExactly(entry1Label, entry2Label);
+ assertThat(BuildType.FILESET_ENTRY_LIST.extractLabels(input)).containsExactly(
+ entry1Label, entry2Label);
}
/**
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java b/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java
index d85bd79d9e..0714c83362 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/TypeTest.java
@@ -59,7 +59,7 @@ public class TypeTest {
public void testInteger() throws Exception {
Object x = 3;
assertEquals(x, Type.INTEGER.convert(x, null));
- assertThat(Type.INTEGER.flatten(x)).isEmpty();
+ assertThat(Type.INTEGER.extractLabels(x)).isEmpty();
}
@Test
@@ -91,7 +91,7 @@ public class TypeTest {
public void testString() throws Exception {
Object s = "foo";
assertEquals(s, Type.STRING.convert(s, null));
- assertThat(Type.STRING.flatten(s)).isEmpty();
+ assertThat(Type.STRING.extractLabels(s)).isEmpty();
}
@Test
@@ -114,7 +114,7 @@ public class TypeTest {
assertTrue(Type.BOOLEAN.convert(myTrue, null));
assertFalse(Type.BOOLEAN.convert(false, null));
assertFalse(Type.BOOLEAN.convert(myFalse, null));
- assertThat(Type.BOOLEAN.flatten(myTrue)).isEmpty();
+ assertThat(Type.BOOLEAN.extractLabels(myTrue)).isEmpty();
}
@Test
@@ -151,7 +151,7 @@ public class TypeTest {
assertEquals(TriState.YES, BuildType.TRISTATE.convert(TriState.YES, null));
assertEquals(TriState.NO, BuildType.TRISTATE.convert(TriState.NO, null));
assertEquals(TriState.AUTO, BuildType.TRISTATE.convert(TriState.AUTO, null));
- assertThat(BuildType.TRISTATE.flatten(TriState.YES)).isEmpty();
+ assertThat(BuildType.TRISTATE.extractLabels(TriState.YES)).isEmpty();
}
@Test
@@ -227,7 +227,7 @@ public class TypeTest {
Label label = Label
.parseAbsolute("//foo:bar");
assertEquals(label, BuildType.LABEL.convert("//foo:bar", null, currentRule));
- assertThat(BuildType.LABEL.flatten(label)).containsExactly(label);
+ assertThat(BuildType.LABEL.extractLabels(label)).containsExactly(label);
}
@Test
@@ -235,7 +235,7 @@ public class TypeTest {
Label label = Label
.parseAbsolute("//foo:bar");
assertEquals(label, BuildType.NODEP_LABEL.convert("//foo:bar", null, currentRule));
- assertThat(BuildType.NODEP_LABEL.flatten(label)).containsExactly(label);
+ assertThat(BuildType.NODEP_LABEL.extractLabels(label)).containsExactly(label);
}
@Test
@@ -279,7 +279,7 @@ public class TypeTest {
Type.STRING_LIST.convert(input, null);
assertEquals(input, converted);
assertNotSame(input, converted);
- assertThat(Type.STRING_LIST.flatten(input)).isEmpty();
+ assertThat(Type.STRING_LIST.extractLabels(input)).isEmpty();
}
@Test
@@ -289,7 +289,7 @@ public class TypeTest {
Map<String, String> converted = Type.STRING_DICT.convert(input, null);
assertEquals(input, converted);
assertNotSame(input, converted);
- assertThat(Type.STRING_DICT.flatten(converted)).isEmpty();
+ assertThat(Type.STRING_DICT.extractLabels(converted)).isEmpty();
}
@Test
@@ -336,7 +336,7 @@ public class TypeTest {
Label.parseAbsolute("//quux:wiz"));
assertEquals(expected, converted);
assertNotSame(expected, converted);
- assertThat(BuildType.LABEL_LIST.flatten(converted)).containsExactlyElementsIn(expected);
+ assertThat(BuildType.LABEL_LIST.extractLabels(converted)).containsExactlyElementsIn(expected);
}
@Test
@@ -385,7 +385,7 @@ public class TypeTest {
"wiz", Arrays.asList("bang"));
assertEquals(expected, converted);
assertNotSame(expected, converted);
- assertThat(Type.STRING_LIST_DICT.flatten(converted)).isEmpty();
+ assertThat(Type.STRING_LIST_DICT.extractLabels(converted)).isEmpty();
}
@Test
@@ -438,7 +438,7 @@ public class TypeTest {
"wiz", "bang");
assertEquals(expected, converted);
assertNotSame(expected, converted);
- assertThat(Type.STRING_DICT_UNARY.flatten(converted)).isEmpty();
+ assertThat(Type.STRING_DICT_UNARY.extractLabels(converted)).isEmpty();
}
@Test