@@ -54,7 +54,9 @@ enum SymbolGraphConcurrentDecoder {
54
54
/// it made sense to spread the work equally (in other words to decode each N-th symbol per worker)
55
55
/// so that we can get the best performance out of the concurrent work.
56
56
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
+
58
60
var symbolGraph : SymbolGraph !
59
61
60
62
let decodeError = Synchronized < Error ? > ( nil )
@@ -67,15 +69,15 @@ enum SymbolGraphConcurrentDecoder {
67
69
group. async ( queue: queue) {
68
70
do {
69
71
// 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
71
73
} catch {
72
74
decodeError. sync ( { $0 = error } )
73
75
}
74
76
}
75
77
76
78
// Concurrently decode each batch of symbols in the graph.
77
79
( 0 ..< concurrentBatches) . concurrentPerform { batchIndex in
78
- let batchDecoder = JSONDecoder ( )
80
+ let batchDecoder = JSONDecoder ( like : decoder )
79
81
80
82
// Configure the decoder to decode the current batch
81
83
batchDecoder. userInfo [ CodingUserInfoKey . symbolCounter] = Counter ( )
@@ -179,3 +181,22 @@ enum SymbolGraphConcurrentDecoder {
179
181
}
180
182
}
181
183
}
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