Skip to content

Commit

Permalink
Index the first-matching component method instead of filtering on eac…
Browse files Browse the repository at this point in the history
…h request.

RELNOTES=Build performance improvements
PiperOrigin-RevId: 361389870
  • Loading branch information
ronshapiro authored and Dagger Team committed Mar 7, 2021
1 parent 1c66033 commit 1caa7f0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 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 @@ -240,19 +242,17 @@ final ComponentDescriptor getChildComponentWithBuilderType(TypeElement builderTy

/** 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();
return Optional.ofNullable(firstMatchingComponentMethods().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
ImmutableMap<BindingRequest, ComponentMethodDescriptor>
firstMatchingComponentMethods() {
Map<BindingRequest, ComponentMethodDescriptor> methods = new HashMap<>();
for (ComponentMethodDescriptor method : entryPointMethods()) {
methods.putIfAbsent(BindingRequest.bindingRequest(method.dependencyRequest().get()), method);
}
return ImmutableMap.copyOf(methods);
}

/** The entry point methods on the component type. Each has a {@link DependencyRequest}. */
Expand Down

0 comments on commit 1caa7f0

Please sign in to comment.