From 154298e9be4fb11a6a96ca409e0a572105edb205 Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Wed, 22 Oct 2025 19:00:21 -0500 Subject: [PATCH] Avoid List and String allocation in inRightLocation The inRightLocation helper was recently optimized to remove Stream usage, however creation of the intermediary List is not necessary at all, and String allocations can be avoided by using equalsIgnoreCase. Additionally, make some other methods static where possible. --- .../idl/SchemaTypeDirectivesChecker.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/graphql/schema/idl/SchemaTypeDirectivesChecker.java b/src/main/java/graphql/schema/idl/SchemaTypeDirectivesChecker.java index 7892efa46..4c3e373e3 100644 --- a/src/main/java/graphql/schema/idl/SchemaTypeDirectivesChecker.java +++ b/src/main/java/graphql/schema/idl/SchemaTypeDirectivesChecker.java @@ -2,7 +2,6 @@ import graphql.GraphQLError; import graphql.Internal; -import graphql.collect.ImmutableKit; import graphql.introspection.Introspection.DirectiveLocation; import graphql.language.Argument; import graphql.language.Directive; @@ -148,10 +147,13 @@ private void checkDirectives(DirectiveLocation expectedLocation, List names = ImmutableKit.map(directiveDefinition.getDirectiveLocations(), - it -> it.getName().toUpperCase()); - return names.contains(expectedLocation.name().toUpperCase()); + private static boolean inRightLocation(DirectiveLocation expectedLocation, DirectiveDefinition directiveDefinition) { + for (graphql.language.DirectiveLocation location : directiveDefinition.getDirectiveLocations()) { + if (location.getName().equalsIgnoreCase(expectedLocation.name())) { + return true; + } + } + return false; } private void checkDirectiveArguments(List errors, TypeDefinitionRegistry typeRegistry, Node element, String elementName, Directive directive, DirectiveDefinition directiveDefinition) { @@ -175,7 +177,7 @@ private void checkDirectiveArguments(List errors, TypeDefinitionRe }); } - private boolean isNoNullArgWithoutDefaultValue(InputValueDefinition definitionArgument) { + private static boolean isNoNullArgWithoutDefaultValue(InputValueDefinition definitionArgument) { return definitionArgument.getType() instanceof NonNullType && definitionArgument.getDefaultValue() == null; } @@ -192,7 +194,7 @@ private void commonCheck(Collection directiveDefinitions, L }); } - private void assertTypeName(NamedNode node, List errors) { + private static void assertTypeName(NamedNode node, List errors) { if (node.getName().length() >= 2 && node.getName().startsWith("__")) { errors.add((new IllegalNameError(node))); } @@ -215,7 +217,7 @@ public void assertExistAndIsInputType(InputValueDefinition definition, List findTypeDefFromRegistry(String typeName, TypeDefinitionRegistry typeRegistry) { + private static TypeDefinition findTypeDefFromRegistry(String typeName, TypeDefinitionRegistry typeRegistry) { TypeDefinition typeDefinition = typeRegistry.getTypeOrNull(typeName); if (typeDefinition != null) { return typeDefinition;