Skip to content

Commit

Permalink
Rename cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kaishin committed Jan 2, 2024
1 parent b9a0a25 commit 21a4e4f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Sources/Gifu/Classes/FrameStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import UIKit
/// Responsible for storing and updating the frames of a single GIF.
class FrameStore {
enum FrameCachingStrategy: Equatable {
case cacheNext(Int)
case cacheAll
case keepUpcoming(Int)
case keepAll
}

/// The caching strategy to use for frames
Expand Down Expand Up @@ -39,11 +39,12 @@ class FrameStore {
/// The content mode to use when resizing.
let contentMode: UIView.ContentMode

/// Maximum number of frames to load at once
/// Maximum number of upcoming frames to pre-load.
/// Defaults to 10 when all frames are cached indefinitely.
var frameBufferSize: Int {
switch cachingStrategy {
case .cacheNext(let size): size
case .cacheAll: 10 // Default to 10 when purging frames is disabled
case .keepUpcoming(let size): size
case .keepAll: 10
}
}

Expand Down Expand Up @@ -112,7 +113,7 @@ class FrameStore {
self.imageSource = CGImageSourceCreateWithData(data as CFData, options) ?? CGImageSourceCreateIncremental(options)
self.size = size
self.contentMode = contentMode
self.cachingStrategy = frameBufferSize > 0 ? .cacheNext(frameBufferSize) : .cacheAll
self.cachingStrategy = frameBufferSize > 0 ? .keepUpcoming(frameBufferSize) : .keepAll
self.loopCount = loopCount
}

Expand Down Expand Up @@ -193,7 +194,7 @@ private extension FrameStore {

/// Updates the frames by preloading new ones and replacing the previous frame with a placeholder.
func updateFrameCache() {
if case let .cacheNext(size) = cachingStrategy,
if case let .keepUpcoming(size) = cachingStrategy,
size < frameCount - 1 {
deleteCachedFrame(at: previousFrameIndex)
}
Expand Down

0 comments on commit 21a4e4f

Please sign in to comment.