mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Optimized Timeline context menu so that it isn't constantly scanning for article location in array
This commit is contained in:
@@ -101,28 +101,30 @@ extension Array where Element == Article {
|
||||
}
|
||||
|
||||
func articlesAbove(article: Article) -> [Article] {
|
||||
guard let position = firstIndex(of: article) else {
|
||||
return []
|
||||
}
|
||||
|
||||
guard let position = firstIndex(of: article) else { return [] }
|
||||
return articlesAbove(position: position)
|
||||
}
|
||||
|
||||
func articlesAbove(position: Int) -> [Article] {
|
||||
guard position < count else { return [] }
|
||||
let articlesAbove = self[..<position]
|
||||
return Array(articlesAbove)
|
||||
}
|
||||
|
||||
func articlesBelow(article: Article) -> [Article] {
|
||||
guard let position = firstIndex(of: article) else {
|
||||
return []
|
||||
}
|
||||
|
||||
guard let position = firstIndex(of: article) else { return [] }
|
||||
return articlesBelow(position: position)
|
||||
}
|
||||
|
||||
func articlesBelow(position: Int) -> [Article] {
|
||||
guard position < count else { return [] }
|
||||
var articlesBelow = Array(self[position...])
|
||||
|
||||
guard !articlesBelow.isEmpty else {
|
||||
return []
|
||||
}
|
||||
|
||||
articlesBelow.removeFirst()
|
||||
|
||||
return articlesBelow
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user