mirror of
https://github.com/apple/sourcekit-lsp.git
synced 2026-03-06 18:24:36 +01:00
Only pass key and not value to LRUCache.removeAll(where:)
The value isn’t needed here and the calls become cleaner if only the key is passed.
This commit is contained in:
@@ -41,15 +41,15 @@ package struct LRUCache<Key: Hashable, Value> {
|
||||
/// A collection containing just the keys of the cache.
|
||||
///
|
||||
/// - Note: Keys will **not** be in the same order that they were added to the cache.
|
||||
package var keys: any Collection<Key> { cache.keys }
|
||||
package var keys: some Collection<Key> { cache.keys }
|
||||
|
||||
/// A collection containing just the values of the cache.
|
||||
///
|
||||
/// - Note: Values will **not** be in the same order that they were added to the cache.
|
||||
package var values: any Collection<Value> { cache.values }
|
||||
package var values: some Collection<Value> { cache.values }
|
||||
|
||||
package init(capacity: Int) {
|
||||
assert(capacity > 0, "LRUCache capacity must be greater than 0")
|
||||
precondition(capacity > 0, "LRUCache capacity must be greater than 0")
|
||||
self.capacity = capacity
|
||||
self.cache = Dictionary(minimumCapacity: capacity)
|
||||
self.priorities = Dictionary(minimumCapacity: capacity)
|
||||
@@ -101,9 +101,9 @@ package struct LRUCache<Key: Hashable, Value> {
|
||||
}
|
||||
|
||||
/// Removes all the elements that satisfy the given predicate.
|
||||
package mutating func removeAll(where shouldBeRemoved: (_: ((key: Key, value: Value)) throws -> Bool)) rethrows {
|
||||
package mutating func removeAll(where shouldBeRemoved: (_ key: Key) throws -> Bool) rethrows {
|
||||
cache = try cache.filter { entry in
|
||||
guard try shouldBeRemoved(entry) else {
|
||||
guard try shouldBeRemoved(entry.key) else {
|
||||
return true
|
||||
}
|
||||
removePriority(forKey: entry.key)
|
||||
|
||||
@@ -95,7 +95,7 @@ actor DiagnosticReportManager {
|
||||
}
|
||||
|
||||
func removeItemsFromCache(with uri: DocumentURI) async {
|
||||
reportTaskCache.removeAll(where: { $0.key.snapshotID.uri == uri })
|
||||
reportTaskCache.removeAll(where: { $0.snapshotID.uri == uri })
|
||||
}
|
||||
|
||||
private func requestReport(
|
||||
@@ -193,7 +193,7 @@ actor DiagnosticReportManager {
|
||||
reportTask: ReportTask
|
||||
) {
|
||||
// Remove any reportTasks for old versions of this document.
|
||||
reportTaskCache.removeAll(where: { $0.key.snapshotID <= snapshotID })
|
||||
reportTaskCache.removeAll(where: { $0.snapshotID <= snapshotID })
|
||||
reportTaskCache[CacheKey(snapshotID: snapshotID, buildSettings: buildSettings)] = reportTask
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ actor MacroExpansionManager {
|
||||
/// Remove all cached macro expansions for the given primary file, eg. because the macro's plugin might have changed.
|
||||
func purge(primaryFile: DocumentURI) {
|
||||
cache.removeAll {
|
||||
$0.key.snapshotID.uri.primaryFile ?? $0.key.snapshotID.uri == primaryFile
|
||||
$0.snapshotID.uri.primaryFile ?? $0.snapshotID.uri == primaryFile
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ actor SyntaxTreeManager {
|
||||
/// Set the task that computes the syntax tree for the given document snapshot.
|
||||
private func setComputation(for snapshotID: DocumentSnapshot.ID, computation: SyntaxTreeComputation) {
|
||||
// Remove any syntax trees for old versions of this document.
|
||||
syntaxTreeComputations.removeAll(where: { key, value in key < snapshotID })
|
||||
syntaxTreeComputations.removeAll(where: { $0 < snapshotID })
|
||||
syntaxTreeComputations[snapshotID] = computation
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ final class LRUCacheTests: XCTestCase {
|
||||
}
|
||||
|
||||
// Remove all even keys
|
||||
lruCache.removeAll(where: { $0.key % 2 == 0 })
|
||||
lruCache.removeAll(where: { $0 % 2 == 0 })
|
||||
assertLRUCacheKeys(lruCache, expectedKeys: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19])
|
||||
|
||||
// Remove all key-value pairs
|
||||
|
||||
Reference in New Issue
Block a user