From 4e157a84f9d299ad422d39f5e2aaaf99f62b352f Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Wed, 6 Nov 2019 01:00:16 +0800 Subject: [PATCH] Check playRate in advance to avoid querying to frame duration --- SDWebImage/Core/SDAnimatedImagePlayer.m | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SDWebImage/Core/SDAnimatedImagePlayer.m b/SDWebImage/Core/SDAnimatedImagePlayer.m index e358f136..228f0087 100644 --- a/SDWebImage/Core/SDAnimatedImagePlayer.m +++ b/SDWebImage/Core/SDAnimatedImagePlayer.m @@ -228,17 +228,18 @@ NSUInteger currentFrameIndex = self.currentFrameIndex; NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount; + NSTimeInterval playRate = self.playRate; + if (playRate <= 0) { + // Does not support <= 0 play rate + [self stopPlaying]; + return; + } + // Check if we have the frame buffer firstly to improve performance if (!self.bufferMiss) { // Then check if timestamp is reached self.currentTime += duration; NSTimeInterval currentDuration = [self.animatedProvider animatedImageDurationAtIndex:currentFrameIndex]; - NSTimeInterval playRate = self.playRate; - if (playRate <= 0) { - // Does not support <= 0 play rate - [self stopPlaying]; - return; - } currentDuration = currentDuration / playRate; if (self.currentTime < currentDuration) { // Current frame timestamp not reached, return