Merge pull request #3118 from huangboju/feature/short_path
Shorten code indentation
This commit is contained in:
commit
ac66153ffb
|
@ -194,7 +194,12 @@ static NSString * _defaultDiskCacheDirectory;
|
||||||
[self.memoryCache setObject:image forKey:key cost:cost];
|
[self.memoryCache setObject:image forKey:key cost:cost];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toDisk) {
|
if (!toDisk) {
|
||||||
|
if (completionBlock) {
|
||||||
|
completionBlock();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
dispatch_async(self.ioQueue, ^{
|
dispatch_async(self.ioQueue, ^{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSData *data = imageData;
|
NSData *data = imageData;
|
||||||
|
@ -211,20 +216,32 @@ static NSString * _defaultDiskCacheDirectory;
|
||||||
format = SDImageFormatGIF;
|
format = SDImageFormatGIF;
|
||||||
} else {
|
} else {
|
||||||
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
||||||
if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) {
|
format = [SDImageCoderHelper CGImageContainsAlpha:image.CGImage] ? SDImageFormatPNG : SDImageFormatJPEG;
|
||||||
format = SDImageFormatPNG;
|
|
||||||
} else {
|
|
||||||
format = SDImageFormatJPEG;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
||||||
}
|
}
|
||||||
[self _storeImageDataToDisk:data forKey:key];
|
[self _storeImageDataToDisk:data forKey:key];
|
||||||
if (image) {
|
[self _archivedDataWithImage:image forKey:key];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completionBlock) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
completionBlock();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)_archivedDataWithImage:(UIImage *)image forKey:(NSString *)key {
|
||||||
|
if (!image) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Check extended data
|
// Check extended data
|
||||||
id extendedObject = image.sd_extendedObject;
|
id extendedObject = image.sd_extendedObject;
|
||||||
if ([extendedObject conformsToProtocol:@protocol(NSCoding)]) {
|
if (![extendedObject conformsToProtocol:@protocol(NSCoding)]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
NSData *extendedData;
|
NSData *extendedData;
|
||||||
if (@available(iOS 11, tvOS 11, macOS 10.13, watchOS 4, *)) {
|
if (@available(iOS 11, tvOS 11, macOS 10.13, watchOS 4, *)) {
|
||||||
NSError *error;
|
NSError *error;
|
||||||
|
@ -246,21 +263,6 @@ static NSString * _defaultDiskCacheDirectory;
|
||||||
[self.diskCache setExtendedData:extendedData forKey:key];
|
[self.diskCache setExtendedData:extendedData forKey:key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (completionBlock) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
|
||||||
completionBlock();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (completionBlock) {
|
|
||||||
completionBlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)storeImageToMemory:(UIImage *)image forKey:(NSString *)key {
|
- (void)storeImageToMemory:(UIImage *)image forKey:(NSString *)key {
|
||||||
if (!image || !key) {
|
if (!image || !key) {
|
||||||
|
@ -414,12 +416,23 @@ static NSString * _defaultDiskCacheDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key data:(nullable NSData *)data options:(SDImageCacheOptions)options context:(SDWebImageContext *)context {
|
- (nullable UIImage *)diskImageForKey:(nullable NSString *)key data:(nullable NSData *)data options:(SDImageCacheOptions)options context:(SDWebImageContext *)context {
|
||||||
if (data) {
|
if (!data) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
UIImage *image = SDImageCacheDecodeImageData(data, key, [[self class] imageOptionsFromCacheOptions:options], context);
|
UIImage *image = SDImageCacheDecodeImageData(data, key, [[self class] imageOptionsFromCacheOptions:options], context);
|
||||||
if (image) {
|
[self _unarchiveObjectWithImage:image forKey:key];
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)_unarchiveObjectWithImage:(UIImage *)image forKey:(NSString *)key {
|
||||||
|
if (!image) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Check extended data
|
// Check extended data
|
||||||
NSData *extendedData = [self.diskCache extendedDataForKey:key];
|
NSData *extendedData = [self.diskCache extendedDataForKey:key];
|
||||||
if (extendedData) {
|
if (!extendedData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
id extendedObject;
|
id extendedObject;
|
||||||
if (@available(iOS 11, tvOS 11, macOS 10.13, watchOS 4, *)) {
|
if (@available(iOS 11, tvOS 11, macOS 10.13, watchOS 4, *)) {
|
||||||
NSError *error;
|
NSError *error;
|
||||||
|
@ -441,12 +454,6 @@ static NSString * _defaultDiskCacheDirectory;
|
||||||
}
|
}
|
||||||
image.sd_extendedObject = extendedObject;
|
image.sd_extendedObject = extendedObject;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (nullable NSOperation *)queryCacheOperationForKey:(NSString *)key done:(SDImageCacheQueryCompletionBlock)doneBlock {
|
- (nullable NSOperation *)queryCacheOperationForKey:(NSString *)key done:(SDImageCacheQueryCompletionBlock)doneBlock {
|
||||||
return [self queryCacheOperationForKey:key options:0 done:doneBlock];
|
return [self queryCacheOperationForKey:key options:0 done:doneBlock];
|
||||||
|
|
Loading…
Reference in New Issue