@@ -54,7 +54,9 @@ enum SymbolGraphConcurrentDecoder {
5454 /// it made sense to spread the work equally (in other words to decode each N-th symbol per worker)
5555 /// so that we can get the best performance out of the concurrent work.
5656
57- static func decode( _ data: Data , concurrentBatches: Int = 4 ) throws -> SymbolGraph {
57+ static func decode( _ data: Data , concurrentBatches: Int = 4 , using decoder: JSONDecoder = JSONDecoder ( ) ) throws -> SymbolGraph {
58+
59+
5860 var symbolGraph : SymbolGraph !
5961
6062 let decodeError = Synchronized < Error ? > ( nil )
@@ -67,15 +69,15 @@ enum SymbolGraphConcurrentDecoder {
6769 group. async ( queue: queue) {
6870 do {
6971 // Decode the symbol graph bar the symbol list.
70- symbolGraph = try JSONDecoder ( ) . decode ( SymbolGraphWithoutSymbols . self, from: data) . symbolGraph
72+ symbolGraph = try JSONDecoder ( like : decoder ) . decode ( SymbolGraphWithoutSymbols . self, from: data) . symbolGraph
7173 } catch {
7274 decodeError. sync ( { $0 = error } )
7375 }
7476 }
7577
7678 // Concurrently decode each batch of symbols in the graph.
7779 ( 0 ..< concurrentBatches) . concurrentPerform { batchIndex in
78- let batchDecoder = JSONDecoder ( )
80+ let batchDecoder = JSONDecoder ( like : decoder )
7981
8082 // Configure the decoder to decode the current batch
8183 batchDecoder. userInfo [ CodingUserInfoKey . symbolCounter] = Counter ( )
@@ -179,3 +181,22 @@ enum SymbolGraphConcurrentDecoder {
179181 }
180182 }
181183}
184+
185+ private extension JSONDecoder {
186+ /// Creates a new decoder with the same configuration as the
187+ /// old one.
188+ convenience init ( like old: JSONDecoder ) {
189+ self . init ( )
190+
191+ self . userInfo = old. userInfo
192+ self . dataDecodingStrategy = old. dataDecodingStrategy
193+ self . dateDecodingStrategy = old. dateDecodingStrategy
194+ self . keyDecodingStrategy = old. keyDecodingStrategy
195+ self . nonConformingFloatDecodingStrategy = old. nonConformingFloatDecodingStrategy
196+
197+ if #available( macOS 12 . 0 , * ) {
198+ self . allowsJSON5 = old. allowsJSON5
199+ self . assumesTopLevelDictionary = old. assumesTopLevelDictionary
200+ }
201+ }
202+ }
0 commit comments