2
0
Эх сурвалжийг харах

Merge pull request #1958 from idrougge/master

Remove unused code
Wei Wang 3 жил өмнө
parent
commit
ccc1fac764

+ 6 - 17
Sources/Cache/ImageCache.swift

@@ -609,12 +609,10 @@ open class ImageCache {
                     image = options.cacheSerializer.image(with: data, options: options)
                     image = options.cacheSerializer.image(with: data, options: options)
                 }
                 }
                 callbackQueue.execute { completionHandler(.success(image)) }
                 callbackQueue.execute { completionHandler(.success(image)) }
+            } catch let error as KingfisherError {
+                callbackQueue.execute { completionHandler(.failure(error)) }
             } catch {
             } catch {
-                if let error = error as? KingfisherError {
-                    callbackQueue.execute { completionHandler(.failure(error)) }
-                } else {
-                    assertionFailure("The internal thrown error should be a `KingfisherError`.")
-                }
+                assertionFailure("The internal thrown error should be a `KingfisherError`.")
             }
             }
         }
         }
     }
     }
@@ -810,13 +808,10 @@ open class ImageCache {
             do {
             do {
                 let size = try self.diskStorage.totalSize()
                 let size = try self.diskStorage.totalSize()
                 DispatchQueue.main.async { handler(.success(size)) }
                 DispatchQueue.main.async { handler(.success(size)) }
+            } catch let error as KingfisherError {
+                DispatchQueue.main.async { handler(.failure(error)) }
             } catch {
             } catch {
-                if let error = error as? KingfisherError {
-                    DispatchQueue.main.async { handler(.failure(error)) }
-                } else {
-                    assertionFailure("The internal thrown error should be a `KingfisherError`.")
-                }
-                
+                assertionFailure("The internal thrown error should be a `KingfisherError`.")
             }
             }
         }
         }
     }
     }
@@ -846,12 +841,6 @@ open class ImageCache {
     }
     }
 }
 }
 
 
-extension Dictionary {
-    func keysSortedByValue(_ isOrderedBefore: (Value, Value) -> Bool) -> [Key] {
-        return Array(self).sorted{ isOrderedBefore($0.1, $1.1) }.map{ $0.0 }
-    }
-}
-
 #if !os(macOS) && !os(watchOS)
 #if !os(macOS) && !os(watchOS)
 // MARK: - For App Extensions
 // MARK: - For App Extensions
 extension UIApplication: KingfisherCompatible { }
 extension UIApplication: KingfisherCompatible { }

+ 6 - 8
Sources/Cache/MemoryStorage.swift

@@ -92,7 +92,7 @@ public enum MemoryStorage {
                     keys.remove(key)
                     keys.remove(key)
                     continue
                     continue
                 }
                 }
-                if object.estimatedExpiration.isPast {
+                if object.isExpired {
                     storage.removeObject(forKey: nsKey)
                     storage.removeObject(forKey: nsKey)
                     keys.remove(key)
                     keys.remove(key)
                 }
                 }
@@ -128,9 +128,9 @@ public enum MemoryStorage {
             
             
             let object: StorageObject<T>
             let object: StorageObject<T>
             if config.keepWhenEnteringBackground {
             if config.keepWhenEnteringBackground {
-                object = BackgroundKeepingStorageObject(value, key: key, expiration: expiration)
+                object = BackgroundKeepingStorageObject(value, expiration: expiration)
             } else {
             } else {
-                object = StorageObject(value, key: key, expiration: expiration)
+                object = StorageObject(value, expiration: expiration)
             }
             }
             storage.setObject(object, forKey: key as NSString, cost: value.cacheCost)
             storage.setObject(object, forKey: key as NSString, cost: value.cacheCost)
             keys.insert(key)
             keys.insert(key)
@@ -146,7 +146,7 @@ public enum MemoryStorage {
             guard let object = storage.object(forKey: key as NSString) else {
             guard let object = storage.object(forKey: key as NSString) else {
                 return nil
                 return nil
             }
             }
-            if object.expired {
+            if object.isExpired {
                 return nil
                 return nil
             }
             }
             object.extendExpiration(extendingExpiration)
             object.extendExpiration(extendingExpiration)
@@ -255,13 +255,11 @@ extension MemoryStorage {
     class StorageObject<T> {
     class StorageObject<T> {
         var value: T?
         var value: T?
         let expiration: StorageExpiration
         let expiration: StorageExpiration
-        let key: String
         
         
         private(set) var estimatedExpiration: Date
         private(set) var estimatedExpiration: Date
         
         
-        init(_ value: T, key: String, expiration: StorageExpiration) {
+        init(_ value: T, expiration: StorageExpiration) {
             self.value = value
             self.value = value
-            self.key = key
             self.expiration = expiration
             self.expiration = expiration
             
             
             self.estimatedExpiration = expiration.estimatedExpirationSinceNow
             self.estimatedExpiration = expiration.estimatedExpirationSinceNow
@@ -278,7 +276,7 @@ extension MemoryStorage {
             }
             }
         }
         }
         
         
-        var expired: Bool {
+        var isExpired: Bool {
             return estimatedExpiration.isPast
             return estimatedExpiration.isPast
         }
         }
     }
     }

+ 0 - 3
Sources/Cache/Storage.swift

@@ -28,9 +28,6 @@ import Foundation
 
 
 /// Constants for some time intervals
 /// Constants for some time intervals
 struct TimeConstants {
 struct TimeConstants {
-    static let secondsInOneMinute = 60
-    static let minutesInOneHour = 60
-    static let hoursInOneDay = 24
     static let secondsInOneDay = 86_400
     static let secondsInOneDay = 86_400
 }
 }
 
 

+ 0 - 7
Sources/General/ImageSource/Source.swift

@@ -113,11 +113,4 @@ extension Source {
         }
         }
         return resource
         return resource
     }
     }
-
-    var asProvider: ImageDataProvider? {
-        guard case .provider(let provider) = self else {
-            return nil
-        }
-        return provider
-    }
 }
 }

+ 0 - 15
Sources/Image/ImageProcessor.swift

@@ -917,19 +917,4 @@ extension KFCrossPlatformColor {
         let components = self.rgba
         let components = self.rgba
         return String(format: "(%.2f,%.2f,%.2f,%.2f)", components.r, components.g, components.b, components.a)
         return String(format: "(%.2f,%.2f,%.2f,%.2f)", components.r, components.g, components.b, components.a)
     }
     }
-    
-    @available(*, deprecated, message: "`hex` is not safe for colors in extended space. Do not use this.")
-    var hex: String {
-        
-        let (r, g, b, a) = rgba
-
-        let rInt = Int(r * 255) << 24
-        let gInt = Int(g * 255) << 16
-        let bInt = Int(b * 255) << 8
-        let aInt = Int(a * 255)
-        
-        let rgba = rInt | gInt | bInt | aInt
-        
-        return String(format:"#%08x", rgba)
-    }
 }
 }

+ 0 - 9
Sources/Image/ImageProgressive.swift

@@ -58,10 +58,6 @@ public struct ImageProgressive {
     }
     }
 }
 }
 
 
-protocol ImageSettable: AnyObject {
-    var image: KFCrossPlatformImage? { get set }
-}
-
 final class ImageProgressiveProvider: DataReceivingSideEffect {
 final class ImageProgressiveProvider: DataReceivingSideEffect {
     
     
     var onShouldApply: () -> Bool = { return true }
     var onShouldApply: () -> Bool = { return true }
@@ -269,7 +265,6 @@ private final class ImageProgressiveSerialQueue {
     private var items: [DispatchWorkItem] = []
     private var items: [DispatchWorkItem] = []
     private var notify: (() -> Void)?
     private var notify: (() -> Void)?
     private var lastTime: TimeInterval?
     private var lastTime: TimeInterval?
-    var count: Int { return items.count }
 
 
     init() {
     init() {
         self.queue = DispatchQueue(label: "com.onevcat.Kingfisher.ImageProgressive.SerialQueue")
         self.queue = DispatchQueue(label: "com.onevcat.Kingfisher.ImageProgressive.SerialQueue")
@@ -314,10 +309,6 @@ private final class ImageProgressiveSerialQueue {
         }
         }
     }
     }
     
     
-    func notify(_ closure: @escaping () -> Void) {
-        self.notify = closure
-    }
-    
     func clean() {
     func clean() {
         queue.async { [weak self] in
         queue.async { [weak self] in
             guard let self = self else { return }
             guard let self = self else { return }

+ 1 - 1
Sources/Networking/ImageDownloader.swift

@@ -268,7 +268,7 @@ open class ImageDownloader {
         // Ready to start download. Add it to session task manager (`sessionHandler`)
         // Ready to start download. Add it to session task manager (`sessionHandler`)
         let downloadTask: DownloadTask
         let downloadTask: DownloadTask
         if let existingTask = sessionDelegate.task(for: context.url) {
         if let existingTask = sessionDelegate.task(for: context.url) {
-            downloadTask = sessionDelegate.append(existingTask, url: context.url, callback: callback)
+            downloadTask = sessionDelegate.append(existingTask, callback: callback)
         } else {
         } else {
             let sessionDataTask = session.dataTask(with: context.request)
             let sessionDataTask = session.dataTask(with: context.request)
             sessionDataTask.priority = context.options.downloadPriority
             sessionDataTask.priority = context.options.downloadPriority

+ 0 - 1
Sources/Networking/SessionDelegate.swift

@@ -91,7 +91,6 @@ open class SessionDelegate: NSObject {
 
 
     func append(
     func append(
         _ task: SessionDataTask,
         _ task: SessionDataTask,
-        url: URL,
         callback: SessionDataTask.TaskCallback) -> DownloadTask
         callback: SessionDataTask.TaskCallback) -> DownloadTask
     {
     {
         let token = task.addCallback(callback)
         let token = task.addCallback(callback)

+ 0 - 8
Sources/Utility/ExtensionHelpers.swift

@@ -104,18 +104,10 @@ extension Date {
         return isPast(referenceDate: Date())
         return isPast(referenceDate: Date())
     }
     }
 
 
-    var isFuture: Bool {
-        return !isPast
-    }
-
     func isPast(referenceDate: Date) -> Bool {
     func isPast(referenceDate: Date) -> Bool {
         return timeIntervalSince(referenceDate) <= 0
         return timeIntervalSince(referenceDate) <= 0
     }
     }
 
 
-    func isFuture(referenceDate: Date) -> Bool {
-        return !isPast(referenceDate: referenceDate)
-    }
-
     // `Date` in memory is a wrap for `TimeInterval`. But in file attribute it can only accept `Int` number.
     // `Date` in memory is a wrap for `TimeInterval`. But in file attribute it can only accept `Int` number.
     // By default the system will `round` it. But it is not friendly for testing purpose.
     // By default the system will `round` it. But it is not friendly for testing purpose.
     // So we always `ceil` the value when used for file attributes.
     // So we always `ceil` the value when used for file attributes.

+ 0 - 21
Sources/Utility/Result.swift

@@ -47,25 +47,4 @@ extension Result where Failure: Error {
             return onFailure(error)
             return onFailure(error)
         }
         }
     }
     }
-
-    func matchSuccess<Output>(with folder: (Success?) -> Output) -> Output {
-        return match(
-            onSuccess: { value in return folder(value) },
-            onFailure: { _ in return folder(nil) }
-        )
-    }
-
-    func matchFailure<Output>(with folder: (Error?) -> Output) -> Output {
-        return match(
-            onSuccess: { _ in return folder(nil) },
-            onFailure: { error in return folder(error) }
-        )
-    }
-
-    func match<Output>(with folder: (Success?, Error?) -> Output) -> Output {
-        return match(
-            onSuccess: { return folder($0, nil) },
-            onFailure: { return folder(nil, $0) }
-        )
-    }
 }
 }

+ 0 - 10
Sources/Utility/String+MD5.swift

@@ -90,15 +90,6 @@ extension Int {
 
 
 }
 }
 
 
-extension NSMutableData {
-
-    // Convenient way to append bytes
-    func appendBytes(_ arrayOfBytes: [UInt8]) {
-        append(arrayOfBytes, length: arrayOfBytes.count)
-    }
-
-}
-
 protocol HashProtocol {
 protocol HashProtocol {
     var message: [UInt8] { get }
     var message: [UInt8] { get }
     // Common part for hash calculation. Prepare header data.
     // Common part for hash calculation. Prepare header data.
@@ -178,7 +169,6 @@ func rotateLeft(_ value: UInt32, bits: UInt32) -> UInt32 {
 
 
 class MD5: HashProtocol {
 class MD5: HashProtocol {
 
 
-    static let size = 16 // 128 / 8
     let message: [UInt8]
     let message: [UInt8]
 
 
     init (_ message: [UInt8]) {
     init (_ message: [UInt8]) {

+ 1 - 1
Tests/KingfisherTests/MemoryStorageTests.swift

@@ -256,7 +256,7 @@ class MemoryStorageTests: XCTestCase {
 
 
     func testStorageObject() {
     func testStorageObject() {
         let now = Date()
         let now = Date()
-        let obj = MemoryStorage.StorageObject(1, key: "1", expiration: .seconds(1))
+        let obj = MemoryStorage.StorageObject(1, expiration: .seconds(1))
         XCTAssertEqual(obj.value, 1)
         XCTAssertEqual(obj.value, 1)
 
 
         XCTAssertEqual(
         XCTAssertEqual(