Skip to content

Commit 0446903

Browse files
refactor(perf): Use first instead of filter
Reduces benchmark `graphql` time by 4%
1 parent 7715249 commit 0446903

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

Sources/GraphQL/Execution/Execute.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,10 +1057,7 @@ func defaultResolve(
10571057
}
10581058

10591059
let mirror = Mirror(reflecting: source)
1060-
guard let value = mirror.getValue(named: info.fieldName) else {
1061-
return nil
1062-
}
1063-
return value
1060+
return mirror.getValue(named: info.fieldName)
10641061
}
10651062

10661063
/**

Sources/GraphQL/SwiftUtilities/Mirror.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func unwrap(_ value: any Sendable) -> (any Sendable)? {
1616

1717
extension Mirror {
1818
func getValue(named key: String) -> (any Sendable)? {
19-
guard let matched = children.filter({ $0.label == key }).first else {
19+
guard let matched = children.first(where: { $0.label == key }) else {
2020
return nil
2121
}
2222

0 commit comments

Comments
 (0)