Skip to content

Commit ad4a715

Browse files
Merge pull request #112 from NeedleInAJayStack/feature/large-query-parsing-performance
Optimizes parsing of large non-UTF8 queries
2 parents dda63e4 + a982b62 commit ad4a715

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/GraphQL/Language/Source.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
* but is mostly useful for clients who store GraphQL documents in
44
* source files; for example, if the GraphQL input is in a file Foo.graphql,
55
* it might be useful for name to be "Foo.graphql".
6+
*
7+
* Note that since Source parsing is heavily UTF8 dependent, the body
8+
* is converted into contiguous UTF8 bytes if necessary for optimal performance.
69
*/
710
public struct Source {
811
public let body: String
912
public let name: String
1013

1114
public init(body: String, name: String = "GraphQL") {
12-
self.body = body
15+
var utf8Body = body
16+
utf8Body.makeContiguousUTF8()
17+
18+
self.body = utf8Body
1319
self.name = name
1420
}
1521
}

0 commit comments

Comments
 (0)