From 759b7322c972e72cc3571b9adeae4b6fb62200cd Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 31 Aug 2018 21:53:53 +0800 Subject: [PATCH] Remove lock tradeoff when get fetchFrame --- SDWebImage/SDAnimatedImageView.m | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SDWebImage/SDAnimatedImageView.m b/SDWebImage/SDAnimatedImageView.m index 0e6c52fd..9c7d4595 100644 --- a/SDWebImage/SDAnimatedImageView.m +++ b/SDWebImage/SDAnimatedImageView.m @@ -689,8 +689,10 @@ static NSUInteger SDDeviceFreeMemory() { // Update the current frame UIImage *currentFrame; + UIImage *fetchFrame; LOCKBLOCK({ currentFrame = self.frameBuffer[@(currentFrameIndex)]; + fetchFrame = currentFrame ? self.frameBuffer[@(nextFrameIndex)] : nil; }); BOOL bufferFull = NO; if (currentFrame) { @@ -744,11 +746,6 @@ static NSUInteger SDDeviceFreeMemory() { fetchFrameIndex = nextFrameIndex; } - UIImage *fetchFrame; - LOCKBLOCK({ - fetchFrame = self.frameBuffer[@(fetchFrameIndex)]; - }); - if (!fetchFrame && !bufferFull && self.fetchQueue.operationCount == 0) { // Prefetch next frame in background queue UIImage *animatedImage = self.animatedImage;