Skip to content

Commit

Permalink
Dagger performance improvements.
Browse files Browse the repository at this point in the history
RELNOTES=Minor improvements to Dagger build performance.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=267871691
  • Loading branch information
bcorso authored and cgdecker committed Sep 12, 2019
1 parent e92edf6 commit f1e2a27
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions java/dagger/internal/codegen/binding/ComponentDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import dagger.model.Scope;
import dagger.producers.CancellationPolicy;
import dagger.producers.ProductionComponent;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
Expand Down Expand Up @@ -238,21 +240,25 @@ final ComponentDescriptor getChildComponentWithBuilderType(TypeElement builderTy

public abstract ImmutableSet<ComponentMethodDescriptor> componentMethods();

/** Returns the first component method associated with this binding request, if one exists. */
public Optional<ComponentMethodDescriptor> firstMatchingComponentMethod(BindingRequest request) {
return componentMethods().stream()
.filter(method -> doesComponentMethodMatch(method, request))
.findFirst();
/**
* Returns the component method associated with this binding request, if one exists.
*
* <p>If multiple component methods are associated with the binding request, this method will
* always return the same (unspecified) one.
*/
public Optional<ComponentMethodDescriptor> matchingComponentMethod(BindingRequest request) {
return Optional.ofNullable(componentMethodsMap().get(request));
}

/** Returns true if the component method matches the binding request. */
private static boolean doesComponentMethodMatch(
ComponentMethodDescriptor componentMethod, BindingRequest request) {
return componentMethod
.dependencyRequest()
.map(BindingRequest::bindingRequest)
.filter(request::equals)
.isPresent();
@Memoized
protected ImmutableMap<BindingRequest, ComponentMethodDescriptor> componentMethodsMap() {
Map<BindingRequest, ComponentMethodDescriptor> componentMethodsMap = new HashMap<>();
for (ComponentMethodDescriptor componentMethod : componentMethods()) {
componentMethod.dependencyRequest()
.map(BindingRequest::bindingRequest)
.ifPresent(bindingRequest -> componentMethodsMap.put(bindingRequest, componentMethod));
}
return ImmutableMap.copyOf(componentMethodsMap);
}

/** The entry point methods on the component type. Each has a {@link DependencyRequest}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ BindingExpression wrapInMethod(
MethodImplementationStrategy methodImplementationStrategy =
methodImplementationStrategy(binding, request);
Optional<ComponentMethodDescriptor> matchingComponentMethod =
graph.componentDescriptor().firstMatchingComponentMethod(request);
graph.componentDescriptor().matchingComponentMethod(request);

if (matchingComponentMethod.isPresent()) {
ComponentMethodDescriptor componentMethod = matchingComponentMethod.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected TypeMirror returnType() {
}

private Optional<ComponentMethodDescriptor> matchingComponentMethod() {
return componentImplementation.componentDescriptor().firstMatchingComponentMethod(request);
return componentImplementation.componentDescriptor().matchingComponentMethod(request);
}

/** Strateg for implementing the body of this method. */
Expand Down

0 comments on commit f1e2a27

Please sign in to comment.