mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-18 20:34:46 +01:00
Use a serial queue for RSImage.scaledForIcon, so we don’t end up having a ton of threads and doing too much at once, which hurts performance. Fix #1489.
This commit is contained in:
parent
4d18c34759
commit
910e14b441
@ -6,6 +6,7 @@
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import RSCore
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#else
|
||||
@ -18,13 +19,8 @@ extension RSImage {
|
||||
|
||||
static let maxIconSize = 48
|
||||
|
||||
static func scaledForIcon(_ data: Data, imageResultBlock: @escaping (RSImage?) -> Void) {
|
||||
DispatchQueue.global(qos: .default).async {
|
||||
let image = RSImage.scaledForIcon(data)
|
||||
DispatchQueue.main.async {
|
||||
imageResultBlock(image)
|
||||
}
|
||||
}
|
||||
static func scaledForIcon(_ data: Data, imageResultBlock: @escaping ImageResultBlock) {
|
||||
IconScalerQueue.shared.scaledForIcon(data, imageResultBlock)
|
||||
}
|
||||
|
||||
static func scaledForIcon(_ data: Data) -> RSImage? {
|
||||
@ -41,3 +37,26 @@ extension RSImage {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - IconScalerQueue
|
||||
|
||||
private class IconScalerQueue {
|
||||
|
||||
static let shared = IconScalerQueue()
|
||||
|
||||
private let queue: DispatchQueue = {
|
||||
let q = DispatchQueue(label: "IconScaler", attributes: .initiallyInactive)
|
||||
q.setTarget(queue: DispatchQueue.global(qos: .default))
|
||||
q.activate()
|
||||
return q
|
||||
}()
|
||||
|
||||
func scaledForIcon(_ data: Data, _ imageResultBlock: @escaping ImageResultBlock) {
|
||||
queue.async {
|
||||
let image = RSImage.scaledForIcon(data)
|
||||
DispatchQueue.main.async {
|
||||
imageResultBlock(image)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user