Skip to content

Commit 40f5889

Browse files
committed
configure SymbolGraphConcurrentDecoder with given JSONDecoder in SymbolGraphLoader
1 parent b946543 commit 40f5889

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphConcurrentDecoder.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Sources/SwiftDocC/Infrastructure/Symbol Graph/SymbolGraphLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct SymbolGraphLoader {
6969
case .concurrentlyAllFiles:
7070
symbolGraph = try decoder.decode(SymbolGraph.self, from: data)
7171
case .concurrentlyEachFileInBatches:
72-
symbolGraph = try SymbolGraphConcurrentDecoder.decode(data)
72+
symbolGraph = try SymbolGraphConcurrentDecoder.decode(data, using: decoder)
7373
}
7474

7575
// `moduleNameFor(_:at:)` is static because it's pure function.

0 commit comments

Comments
 (0)