Skip to content

Commit d246f7b

Browse files
swalkinshawclaude
andcommitted
Optimize add_conflict node identity check
Use object identity (equal?) as fast path before falling back to the expensive AST node #== comparison. Most conflict checks involve the same node object, making the identity check sufficient. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bf533a8 commit d246f7b

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/graphql/static_validation/rules/fields_will_merge_error.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def conflicts
2828
end
2929

3030
def add_conflict(node, conflict_str)
31-
# Can't use `.include?` here because AST nodes implement `#==`
32-
# based on string value, not including location. But sometimes,
33-
# identical nodes conflict because of their differing return types.
34-
if nodes.any? { |n| n == node && n.line == node.line && n.col == node.col }
31+
# Check if we already have an error for this exact node.
32+
# Use object identity first (fast path), then fall back to
33+
# value + location comparison for duplicate AST nodes.
34+
if nodes.any? { |n| n.equal?(node) || (n.line == node.line && n.col == node.col && n == node) }
3535
# already have an error for this node
3636
return
3737
end

0 commit comments

Comments
 (0)