From 2fa77435c16e19add517689ea9385e47cdd2ef96 Mon Sep 17 00:00:00 2001 From: Bogdan Poplauschi Date: Fri, 23 Sep 2016 23:54:23 +0300 Subject: [PATCH] Proper place for the pragma mark and used a function to check for the proper queue --- SDWebImage/SDImageCache.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 64b31128..53c924e2 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -136,6 +136,12 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { SDDispatchQueueRelease(_ioQueue); } +- (void)checkIfQueueIsIOQueue { + const char *currentQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); + const char *ioQueueLabel = dispatch_queue_get_label(self.ioQueue); + NSAssert(strcmp(currentQueueLabel, ioQueueLabel) == 0, @"This method should be called from the ioQueue"); +} + #pragma mark - Cache paths - (void)addReadOnlyCachePath:(nonnull NSString *)path { @@ -236,9 +242,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { return; } - const char *currentQueueLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL); - const char *ioQueueLabel = dispatch_queue_get_label(self.ioQueue); - NSAssert(strcmp(currentQueueLabel, ioQueueLabel) == 0, @"This method should be called from the ioQueue"); + [self checkIfQueueIsIOQueue]; if (![_fileManager fileExistsAtPath:_diskCachePath]) { [_fileManager createDirectoryAtPath:_diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL]; @@ -257,6 +261,8 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { } } +#pragma mark - Query and Retrieve Ops + - (void)diskImageExistsWithKey:(nullable NSString *)key completion:(nullable SDWebImageCheckCacheCompletionBlock)completionBlock { dispatch_async(_ioQueue, ^{ BOOL exists = [_fileManager fileExistsAtPath:[self defaultCachePathForKey:key]]; @@ -275,8 +281,6 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { }); } -#pragma mark - Query and Retrieve Ops - - (nullable UIImage *)imageFromMemoryCacheForKey:(nullable NSString *)key { return [self.memCache objectForKey:key]; }