Skip to content

Commit b969ffc

Browse files
authored
Remove unused code in NavigatorTree (#961)
* Remove unused interfaceLanguages parameter in NavigatorTree * Remove assign-only readingCursor property in NavigatorTree
1 parent 1e8eb0a commit b969ffc

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ public class NavigatorIndex {
189189
navigatorTree = try NavigatorTree.read(
190190
from: url.appendingPathComponent("navigator.index", isDirectory: false),
191191
bundleIdentifier: bundleIdentifier,
192-
interfaceLanguages: availabilityIndex.interfaceLanguages,
193192
presentationIdentifier: presentationIdentifier,
194193
onNodeRead: onNodeRead)
195194
} else {
@@ -394,7 +393,7 @@ public class NavigatorIndex {
394393
*/
395394
public func readNavigatorTree(timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, broadcast: NavigatorTree.BroadcastCallback?) throws {
396395
let indexURL = url.appendingPathComponent("navigator.index")
397-
try navigatorTree.read(from: indexURL, bundleIdentifier: bundleIdentifier, interfaceLanguages: availabilityIndex.interfaceLanguages, timeout: timeout, delay: delay, queue: queue, broadcast: broadcast)
396+
try navigatorTree.read(from: indexURL, bundleIdentifier: bundleIdentifier, timeout: timeout, delay: delay, queue: queue, broadcast: broadcast)
398397
}
399398

400399
// MARK: - Data Query

Sources/SwiftDocC/Indexing/Navigator/NavigatorTree.swift

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,23 @@ public class NavigatorTree {
9999
/// The broadcast callback notifies a listener about the latest items loaded from the disk.
100100
public typealias BroadcastCallback = (_ items: [NavigatorTree.Node], _ isCompleted: Bool, _ error: Error?) -> Void
101101

102-
// A reference to the reading cursor.
103-
internal var readingCursor: ReadingCursor? = nil
104-
105102
/**
106103
Read a tree from disk from a given path.
107104
The read is atomically performed, which means it reads all the content of the file from the disk and process the tree from loaded data.
108105

109106
- Parameters:
110107
- url: The file URL from which the tree should be read.
111108
- bundleIdentifier: The bundle identifier used to generate the mapping topicID to node on tree.
112-
- interfaceLanguages: A set containing the indication about the interface languages a tree contains.
113109
- timeout: The amount of time we can load a batch of items from data, once the timeout time pass,
114110
the reading process will reschedule asynchronously using the given queue.
115111
- delay: The delay to wait before schedule the next read. Default: 0.01 seconds.
116112
- queue: The queue to use.
117113
- presentationIdentifier: Defines if nodes should have a presentation identifier useful in presentation contexts.
118114
- broadcast: The callback to update get updates of the current process.
119115
*/
120-
public func read(from url: URL, bundleIdentifier: String? = nil, interfaceLanguages: Set<InterfaceLanguage>, timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, presentationIdentifier: String? = nil, broadcast: BroadcastCallback?) throws {
116+
public func read(from url: URL, bundleIdentifier: String? = nil, timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, presentationIdentifier: String? = nil, broadcast: BroadcastCallback?) throws {
121117
let data = try Data(contentsOf: url)
122118
let readingCursor = ReadingCursor(data: data)
123-
self.readingCursor = readingCursor
124119

125120
func __read() {
126121
let deadline = DispatchTime.now() + timeout
@@ -141,7 +136,6 @@ public class NavigatorTree {
141136

142137
guard let item = NavigatorItem(rawValue: objectData) else {
143138
broadcast?(processedNodes, false, Error.invalidData)
144-
self.readingCursor = nil
145139
break
146140
}
147141

@@ -171,7 +165,6 @@ public class NavigatorTree {
171165
queue.async(flags: .barrier) {
172166
broadcast?(processedNodes, true, nil)
173167
}
174-
self.readingCursor = nil
175168
}
176169
}
177170

@@ -183,6 +176,11 @@ public class NavigatorTree {
183176

184177
self.root = root
185178
}
179+
180+
@available(*, deprecated, renamed: "read(from:bundleIdentifier:timeout:delay:queue:presentationIdentifier:broadcast:)", message: "Use 'read(from:bundleIdentifier:timeout:delay:queue:presentationIdentifier:broadcast:)' instead. This deprecated API will be removed after 6.1 is released")
181+
public func read(from url: URL, bundleIdentifier: String? = nil, interfaceLanguages: Set<InterfaceLanguage>, timeout: TimeInterval, delay: TimeInterval = 0.01, queue: DispatchQueue, presentationIdentifier: String? = nil, broadcast: BroadcastCallback?) throws {
182+
try self.read(from: url, bundleIdentifier: bundleIdentifier, timeout: timeout, delay: delay, queue: queue, presentationIdentifier: presentationIdentifier, broadcast: broadcast)
183+
}
186184

187185
/**
188186
Serialize the node and descendants to the disk.
@@ -261,33 +259,28 @@ public class NavigatorTree {
261259
- Parameters:
262260
- url: The file URL from which the tree should be read.
263261
- bundleIdentifier: The bundle identifier used to generate the mapping topicID to node on tree.
264-
- interfaceLanguages: A set containing the indication about the interface languages a tree contains.
265262
- atomically: Defines if the read should be atomic.
266263
- presentationIdentifier: Defines if nodes should have a presentation identifier useful in presentation contexts.
267264
- onNodeRead: An action to perform after reading a node. This allows clients to perform arbitrary actions on the node while it is being read from disk. This is useful for clients wanting to attach data to ``NavigatorTree/Node/attributes``.
268265
*/
269266
static func read(
270267
from url: URL,
271268
bundleIdentifier: String? = nil,
272-
interfaceLanguages: Set<InterfaceLanguage>,
273269
atomically: Bool = true,
274270
presentationIdentifier: String? = nil,
275271
onNodeRead: ((NavigatorTree.Node) -> Void)? = nil
276272
) throws -> NavigatorTree {
277-
let interfaceLanguageMap = Dictionary(uniqueKeysWithValues: interfaceLanguages.map{ ($0.mask, $0)})
278273
let path = url.path
279274
if atomically {
280275
return try readAtomically(
281276
from: path,
282277
bundleIdentifier: bundleIdentifier,
283-
interfaceLanguageMap: interfaceLanguageMap,
284278
presentationIdentifier: presentationIdentifier,
285279
onNodeRead: onNodeRead)
286280
}
287281
return try read(
288282
from: path,
289283
bundleIdentifier: bundleIdentifier,
290-
interfaceLanguageMap: interfaceLanguageMap,
291284
presentationIdentifier: presentationIdentifier,
292285
onNodeRead: onNodeRead)
293286
}
@@ -296,7 +289,6 @@ public class NavigatorTree {
296289
fileprivate static func readAtomically(
297290
from path: String,
298291
bundleIdentifier: String? = nil,
299-
interfaceLanguageMap: [InterfaceLanguage.ID: InterfaceLanguage],
300292
presentationIdentifier: String? = nil,
301293
onNodeRead: ((NavigatorTree.Node) -> Void)? = nil
302294
) throws -> NavigatorTree {
@@ -347,7 +339,6 @@ public class NavigatorTree {
347339
fileprivate static func read(
348340
from path: String,
349341
bundleIdentifier: String? = nil,
350-
interfaceLanguageMap: [InterfaceLanguage.ID: InterfaceLanguage],
351342
presentationIdentifier: String? = nil,
352343
onNodeRead: ((NavigatorTree.Node) -> Void)? = nil
353344
) throws -> NavigatorTree {

Tests/SwiftDocCTests/Indexing/NavigatorIndexTests.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Root
174174

175175
let original = NavigatorTree(root: root)
176176
try original.write(to: indexURL)
177-
let readTree = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, interfaceLanguages: [.swift], atomically: true)
177+
let readTree = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, atomically: true)
178178

179179
XCTAssertEqual(original.root.countItems(), readTree.root.countItems())
180180
XCTAssertTrue(compare(lhs: original.root, rhs: readTree.root))
@@ -195,7 +195,7 @@ Root
195195
XCTAssertTrue(validateTree(node: readTree.root, validator: bundleIdentifierValidator), "The tree has bundle identifier missing.")
196196
XCTAssertTrue(validateTree(node: readTree.root, validator: emptyPresentationIdentifierValidator), "The tree has a presentation identifier set which should not be present.")
197197

198-
let treeWithPresentationIdentifier = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, interfaceLanguages: [.swift], atomically: true, presentationIdentifier: "com.example.test")
198+
let treeWithPresentationIdentifier = try NavigatorTree.read(from: indexURL, bundleIdentifier: testBundleIdentifier, atomically: true, presentationIdentifier: "com.example.test")
199199

200200
let presentationIdentifierValidator: (NavigatorTree.Node) -> Bool = { node in
201201
return node.presentationIdentifier == "com.example.test"
@@ -213,7 +213,6 @@ Root
213213
let treeWithAttributes = try NavigatorTree.read(
214214
from: indexURL,
215215
bundleIdentifier: testBundleIdentifier,
216-
interfaceLanguages: [.swift],
217216
atomically: true,
218217
presentationIdentifier: "com.example.test",
219218
onNodeRead: addAttributes
@@ -232,7 +231,6 @@ Root
232231
let treeWithAttributesNonAtomic = try NavigatorTree.read(
233232
from: indexURL,
234233
bundleIdentifier: testBundleIdentifier,
235-
interfaceLanguages: [.swift],
236234
atomically: false,
237235
presentationIdentifier: "com.example.test",
238236
onNodeRead: addAttributes
@@ -257,7 +255,6 @@ Root
257255
_ = try NavigatorTree.read(
258256
from: indexURL,
259257
bundleIdentifier: uniqueTestBundleIdentifier,
260-
interfaceLanguages: [.swift],
261258
atomically: true
262259
)
263260

@@ -275,7 +272,7 @@ Root
275272
try original.write(to: indexURL)
276273

277274
measure {
278-
_ = try! NavigatorTree.read(from: indexURL, interfaceLanguages: [.swift], atomically: true)
275+
_ = try! NavigatorTree.read(from: indexURL, atomically: true)
279276
}
280277
#endif
281278
}
@@ -297,7 +294,7 @@ Root
297294
let expectation = XCTestExpectation(description: "Load the tree asynchronously.")
298295

299296
let readTree = NavigatorTree()
300-
try! readTree.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in
297+
try! readTree.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in
301298
counter += 1
302299
XCTAssertNil(error)
303300
if completed { expectation.fulfill() }
@@ -310,7 +307,7 @@ Root
310307

311308
let expectation2 = XCTestExpectation(description: "Load the tree asynchronously, again with presentation identifier.")
312309
let readTreePresentationIdentifier = NavigatorTree()
313-
try! readTreePresentationIdentifier.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main, presentationIdentifier: "com.example.test") { (nodes, completed, error) in
310+
try! readTreePresentationIdentifier.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main, presentationIdentifier: "com.example.test") { (nodes, completed, error) in
314311
XCTAssertNil(error)
315312
if completed { expectation2.fulfill() }
316313
}
@@ -336,7 +333,7 @@ Root
336333
let indexURL = targetURL.appendingPathComponent("nav.index")
337334

338335
let readTree = NavigatorTree()
339-
XCTAssertThrowsError(try readTree.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main, broadcast: nil))
336+
XCTAssertThrowsError(try readTree.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main, broadcast: nil))
340337

341338
try XCTAssertEqual(
342339
RenderIndex.fromURL(targetURL.appendingPathComponent("index.json")),
@@ -371,7 +368,7 @@ Root
371368
let expectation = XCTestExpectation(description: "Load the tree asynchronously.")
372369

373370
let readTree = NavigatorTree()
374-
try! readTree.read(from: indexURL, interfaceLanguages: [.swift], timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in
371+
try! readTree.read(from: indexURL, timeout: 0.25, queue: DispatchQueue.main) { (nodes, completed, error) in
375372
counter += 1
376373
XCTAssertNil(error)
377374
if completed { expectation.fulfill() }

0 commit comments

Comments
 (0)