Skip to content

Commit

Permalink
Fix instances of incorrectly sized Maps and Sets (#2798)
Browse files Browse the repository at this point in the history
Fix a few occurrences where a Map or Set was initialized with an initial capacity
value N, and then immediately filled with N items, which would always trigger
a resize.
  • Loading branch information
kilink authored Apr 17, 2022
1 parent 2c39728 commit 9bf8487
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql.execution.instrumentation;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.PublicApi;
Expand Down Expand Up @@ -210,7 +211,7 @@ private static class ChainedInstrumentationState implements InstrumentationState


private ChainedInstrumentationState(List<Instrumentation> instrumentations, InstrumentationCreateStateParameters parameters) {
instrumentationStates = new LinkedHashMap<>(instrumentations.size());
instrumentationStates = Maps.newLinkedHashMapWithExpectedSize(instrumentations.size());
instrumentations.forEach(i -> instrumentationStates.put(i, i.createState(parameters)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.validation.rules;

import com.google.common.collect.Sets;
import graphql.Internal;
import graphql.language.Argument;
import graphql.language.Directive;
Expand All @@ -10,7 +11,6 @@
import graphql.validation.ValidationErrorCollector;
import graphql.validation.ValidationErrorType;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand All @@ -31,7 +31,7 @@ public void checkField(Field field) {
return;
}

Set<String> arguments = new HashSet<>();
Set<String> arguments = Sets.newHashSetWithExpectedSize(field.getArguments().size());

for (Argument argument : field.getArguments()) {
if (arguments.contains(argument.getName())) {
Expand All @@ -48,7 +48,7 @@ public void checkDirective(Directive directive, List<Node> ancestors) {
return;
}

Set<String> arguments = new HashSet<>(directive.getArguments().size());
Set<String> arguments = Sets.newHashSetWithExpectedSize(directive.getArguments().size());

for (Argument argument : directive.getArguments()) {
if (arguments.contains(argument.getName())) {
Expand Down

0 comments on commit 9bf8487

Please sign in to comment.