mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-05 12:13:02 +00:00
A couple performance tweaks for animated images #trivial (#634)
* A couple performance tweaks for animated images * @nguyenhuy's comments * Avoid calling animatedImageData twice. Thanks @maicki. * Fix call to background deallocation * Good catch by @Adlai-Holler
This commit is contained in:
parent
c1f517a7eb
commit
0b6d41f872
@ -55,6 +55,7 @@ NSString *const ASAnimatedImageDefaultRunLoopMode = NSRunLoopCommonModes;
|
||||
}
|
||||
|
||||
id <ASAnimatedImageProtocol> previousAnimatedImage = _animatedImage;
|
||||
|
||||
_animatedImage = animatedImage;
|
||||
|
||||
if (animatedImage != nil) {
|
||||
@ -80,6 +81,11 @@ NSString *const ASAnimatedImageDefaultRunLoopMode = NSRunLoopCommonModes;
|
||||
}
|
||||
|
||||
[self animatedImageSet:_animatedImage previousAnimatedImage:previousAnimatedImage];
|
||||
|
||||
// Animated image can take while to dealloc, do it off the main queue
|
||||
if (previousAnimatedImage != nil) {
|
||||
ASPerformBackgroundDeallocation(&previousAnimatedImage);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)animatedImageSet:(id <ASAnimatedImageProtocol>)newAnimatedImage previousAnimatedImage:(id <ASAnimatedImageProtocol>)previousAnimatedImage
|
||||
|
@ -713,7 +713,7 @@
|
||||
} else {
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
auto finished = ^(id <ASImageContainerProtocol>imageContainer, NSError *error, id downloadIdentifier, ASNetworkImageSource imageSource) {
|
||||
|
||||
ASPerformBlockOnBackgroundThread(^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf == nil) {
|
||||
return;
|
||||
@ -736,8 +736,9 @@
|
||||
|
||||
if (imageContainer != nil) {
|
||||
[strongSelf _locked_setCurrentImageQuality:1.0];
|
||||
if ([imageContainer asdk_animatedImageData] && strongSelf->_downloaderFlags.downloaderImplementsAnimatedImage) {
|
||||
id animatedImage = [strongSelf->_downloader animatedImageWithData:[imageContainer asdk_animatedImageData]];
|
||||
NSData *animatedImageData = [imageContainer asdk_animatedImageData];
|
||||
if (animatedImageData && strongSelf->_downloaderFlags.downloaderImplementsAnimatedImage) {
|
||||
id animatedImage = [strongSelf->_downloader animatedImageWithData:animatedImageData];
|
||||
[strongSelf _locked_setAnimatedImage:animatedImage];
|
||||
} else {
|
||||
[strongSelf _locked__setImage:[imageContainer asdk_image]];
|
||||
@ -748,6 +749,15 @@
|
||||
strongSelf->_downloadIdentifier = nil;
|
||||
strongSelf->_cacheUUID = nil;
|
||||
|
||||
ASPerformBlockOnMainThread(^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab the lock for the rest of the block
|
||||
ASDN::MutexLocker l(strongSelf->__instanceLock__);
|
||||
|
||||
if (imageContainer != nil) {
|
||||
if (strongSelf->_delegateFlags.delegateDidLoadImageWithInfo) {
|
||||
ASDN::MutexUnlocker u(strongSelf->__instanceLock__);
|
||||
@ -762,6 +772,8 @@
|
||||
ASDN::MutexUnlocker u(strongSelf->__instanceLock__);
|
||||
[delegate imageNode:strongSelf didFailWithError:error];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// As the _cache and _downloader is only set once in the intializer we don't have to use a
|
||||
|
Loading…
x
Reference in New Issue
Block a user