Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASNetworkImageNode] Replace NSUUID sentinel with integer #trivial #852

Merged
merged 3 commits into from
Mar 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ @interface ASNetworkImageNode ()
NSURL *_URL;
UIImage *_defaultImage;

NSUUID *_cacheUUID;
NSInteger _cacheSentinel;
id _downloadIdentifier;
// The download identifier that we have set a progress block on, if any.
id _downloadIdentifierForProgressBlock;
Expand Down Expand Up @@ -536,8 +536,7 @@ - (void)_locked_cancelImageDownloadWithResumePossibility:(BOOL)storeResume
}
}
_downloadIdentifier = nil;

_cacheUUID = nil;
_cacheSentinel++;
}

- (void)_downloadImageWithCompletion:(void (^)(id <ASImageContainerProtocol> imageContainer, NSError*, id downloadIdentifier, id userInfo))finished
Expand Down Expand Up @@ -685,7 +684,7 @@ - (void)_lazilyLoadImageIfNecessary
//No longer in preload range, no point in setting the results (they won't be cleared in exit preload range)
if (ASInterfaceStateIncludesPreload(strongSelf->_interfaceState) == NO) {
strongSelf->_downloadIdentifier = nil;
strongSelf->_cacheUUID = nil;
strongSelf->_cacheSentinel++;
return;
}

Expand All @@ -704,7 +703,7 @@ - (void)_lazilyLoadImageIfNecessary
}

strongSelf->_downloadIdentifier = nil;
strongSelf->_cacheUUID = nil;
strongSelf->_cacheSentinel++;

void (^calloutBlock)(ASNetworkImageNode *inst);

Expand Down Expand Up @@ -738,16 +737,13 @@ - (void)_lazilyLoadImageIfNecessary
// As the _cache and _downloader is only set once in the intializer we don't have to use a
// lock in here
if (_cache != nil) {
NSUUID *cacheUUID = [NSUUID UUID];
ASLockedSelf(_cacheUUID = cacheUUID);
NSInteger cacheSentinel = ASLockedSelf(++_cacheSentinel);

as_log_verbose(ASImageLoadingLog(), "Decaching image for %@ url: %@", self, URL);

ASImageCacherCompletion completion = ^(id <ASImageContainerProtocol> imageContainer) {
// If the cache UUID changed, that means this request was cancelled.
auto currentCacheUUID = ASLockedSelf(_cacheUUID);

if (!ASObjectIsEqual(currentCacheUUID, cacheUUID)) {
// If the cache sentinel changed, that means this request was cancelled.
if (ASLockedSelf(_cacheSentinel != cacheSentinel)) {
return;
}

Expand Down