Skip to content

Commit 01b880b

Browse files
authored
Merge pull request #4149 from kilink/is-right-location-allocations
Avoid List and String allocation in inRightLocation
2 parents e3d1974 + 154298e commit 01b880b

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/main/java/graphql/schema/idl/SchemaTypeDirectivesChecker.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import graphql.GraphQLError;
44
import graphql.Internal;
5-
import graphql.collect.ImmutableKit;
65
import graphql.introspection.Introspection.DirectiveLocation;
76
import graphql.language.Argument;
87
import graphql.language.Directive;
@@ -148,10 +147,13 @@ private void checkDirectives(DirectiveLocation expectedLocation, List<GraphQLErr
148147
});
149148
}
150149

151-
private boolean inRightLocation(DirectiveLocation expectedLocation, DirectiveDefinition directiveDefinition) {
152-
List<String> names = ImmutableKit.map(directiveDefinition.getDirectiveLocations(),
153-
it -> it.getName().toUpperCase());
154-
return names.contains(expectedLocation.name().toUpperCase());
150+
private static boolean inRightLocation(DirectiveLocation expectedLocation, DirectiveDefinition directiveDefinition) {
151+
for (graphql.language.DirectiveLocation location : directiveDefinition.getDirectiveLocations()) {
152+
if (location.getName().equalsIgnoreCase(expectedLocation.name())) {
153+
return true;
154+
}
155+
}
156+
return false;
155157
}
156158

157159
private void checkDirectiveArguments(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Node<?> element, String elementName, Directive directive, DirectiveDefinition directiveDefinition) {
@@ -175,7 +177,7 @@ private void checkDirectiveArguments(List<GraphQLError> errors, TypeDefinitionRe
175177
});
176178
}
177179

178-
private boolean isNoNullArgWithoutDefaultValue(InputValueDefinition definitionArgument) {
180+
private static boolean isNoNullArgWithoutDefaultValue(InputValueDefinition definitionArgument) {
179181
return definitionArgument.getType() instanceof NonNullType && definitionArgument.getDefaultValue() == null;
180182
}
181183

@@ -192,7 +194,7 @@ private void commonCheck(Collection<DirectiveDefinition> directiveDefinitions, L
192194
});
193195
}
194196

195-
private void assertTypeName(NamedNode<?> node, List<GraphQLError> errors) {
197+
private static void assertTypeName(NamedNode<?> node, List<GraphQLError> errors) {
196198
if (node.getName().length() >= 2 && node.getName().startsWith("__")) {
197199
errors.add((new IllegalNameError(node)));
198200
}
@@ -215,7 +217,7 @@ public void assertExistAndIsInputType(InputValueDefinition definition, List<Grap
215217
}
216218
}
217219

218-
private TypeDefinition<?> findTypeDefFromRegistry(String typeName, TypeDefinitionRegistry typeRegistry) {
220+
private static TypeDefinition<?> findTypeDefFromRegistry(String typeName, TypeDefinitionRegistry typeRegistry) {
219221
TypeDefinition<?> typeDefinition = typeRegistry.getTypeOrNull(typeName);
220222
if (typeDefinition != null) {
221223
return typeDefinition;

0 commit comments

Comments
 (0)