Skip to content

Commit 49c23e1

Browse files
committed
Simplify Cache.purge()
1 parent e0a41b0 commit 49c23e1

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

Xit/Utils/Cache.swift

+2-10
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,9 @@ class Cache<Key: Hashable, Value>
6161
func purge(forAdditionalSpace space: Int)
6262
{
6363
while contents.count + space > maxSize {
64-
var oldestDate: Date?
65-
var oldestKey: Key?
66-
67-
for (key, wrapper) in contents {
68-
if oldestDate == nil ||
69-
oldestDate?.compare(wrapper.accessed) == .orderedDescending {
70-
oldestDate = wrapper.accessed
71-
oldestKey = key
72-
}
64+
if let oldest = contents.min(by: { $0.value.accessed < $1.value.accessed }) {
65+
contents[oldest.key] = nil
7366
}
74-
oldestKey.map { contents[$0] = nil }
7567
}
7668
}
7769
}

0 commit comments

Comments
 (0)