Skip to content

Commit

Permalink
Pass SubcomponentDeclarations instead of TypeElements to Subcomponent…
Browse files Browse the repository at this point in the history
…CreatorBindingEdgeImpl.

This set is expensive to create and is only used for error messages.

RELNOTES=Build performance improvements

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=244047548
  • Loading branch information
ronshapiro committed Apr 18, 2019
1 parent fcd069c commit 7e374b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
16 changes: 2 additions & 14 deletions java/dagger/internal/codegen/BindingGraphConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static com.google.auto.common.MoreTypes.asTypeElement;
import static dagger.internal.codegen.BindingRequest.bindingRequest;
import static dagger.internal.codegen.DaggerGraphs.unreachableNodes;
import static dagger.internal.codegen.DaggerStreams.presentValues;
import static dagger.internal.codegen.DaggerStreams.toImmutableSet;
import static dagger.model.BindingKind.SUBCOMPONENT_CREATOR;

import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -103,15 +101,15 @@ protected void visitComponent(BindingGraph graph) {
network.addNode(currentComponent);

for (ResolvedBindings resolvedBindings : graph.resolvedBindings()) {
ImmutableSet<TypeElement> declaringModules = subcomponentDeclaringModules(resolvedBindings);
for (BindingNode binding : bindingNodes(resolvedBindings)) {
addBinding(binding);
if (binding.kind().equals(SUBCOMPONENT_CREATOR)
&& binding.componentPath().equals(currentComponent.componentPath())) {
network.addEdge(
binding,
subcomponentNode(binding.key().type(), graph),
new SubcomponentCreatorBindingEdgeImpl(declaringModules));
new SubcomponentCreatorBindingEdgeImpl(
resolvedBindings.subcomponentDeclarations()));
}
}
}
Expand Down Expand Up @@ -229,15 +227,5 @@ private ComponentNode subcomponentNode(TypeMirror subcomponentBuilderType, Bindi
return ComponentNodeImpl.create(
componentPath().childPath(subcomponent.typeElement()), subcomponent);
}

private ImmutableSet<TypeElement> subcomponentDeclaringModules(
ResolvedBindings resolvedBindings) {
return resolvedBindings
.subcomponentDeclarations()
.stream()
.map(SubcomponentDeclaration::contributingModule)
.flatMap(presentValues())
.collect(toImmutableSet());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package dagger.internal.codegen;

import static com.google.common.collect.Iterables.getOnlyElement;
import static dagger.internal.codegen.DaggerStreams.presentValues;
import static dagger.internal.codegen.DaggerStreams.toImmutableSet;
import static java.util.stream.Collectors.joining;

import com.google.common.collect.ImmutableSet;
Expand All @@ -26,23 +28,27 @@
/** An implementation of {@link SubcomponentCreatorBindingEdge}. */
final class SubcomponentCreatorBindingEdgeImpl implements SubcomponentCreatorBindingEdge {

private final ImmutableSet<TypeElement> declaringModules;
private final ImmutableSet<SubcomponentDeclaration> subcomponentDeclarations;

SubcomponentCreatorBindingEdgeImpl(Iterable<TypeElement> declaringModules) {
this.declaringModules = ImmutableSet.copyOf(declaringModules);
SubcomponentCreatorBindingEdgeImpl(
ImmutableSet<SubcomponentDeclaration> subcomponentDeclarations) {
this.subcomponentDeclarations = subcomponentDeclarations;
}

@Override
public ImmutableSet<TypeElement> declaringModules() {
return declaringModules;
return subcomponentDeclarations.stream()
.map(SubcomponentDeclaration::contributingModule)
.flatMap(presentValues())
.collect(toImmutableSet());
}

@Override
public String toString() {
return "subcomponent declared by "
+ (declaringModules.size() == 1
? getOnlyElement(declaringModules).getQualifiedName()
: declaringModules.stream()
+ (subcomponentDeclarations.size() == 1
? getOnlyElement(declaringModules()).getQualifiedName()
: declaringModules().stream()
.map(TypeElement::getQualifiedName)
.collect(joining(", ", "{", "}")));
}
Expand Down

0 comments on commit 7e374b5

Please sign in to comment.