[NFC] A little optimization for MutableArray creation

This commit is contained in:
DreamPiggy 2022-09-26 17:34:55 +08:00
parent 347cf1d1cc
commit 9b2ddc9ea8
3 changed files with 7 additions and 4 deletions

View File

@ -173,7 +173,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
return nil;
}
NSMutableArray<SDImageFrame *> *frames = [NSMutableArray array];
NSMutableArray<SDImageFrame *> *frames;
NSUInteger frameCount = 0;
#if SD_UIKIT || SD_WATCH
@ -182,6 +182,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
if (frameCount == 0) {
return nil;
}
frames = [NSMutableArray arrayWithCapacity:frameCount];
NSTimeInterval avgDuration = animatedImage.duration / frameCount;
if (avgDuration == 0) {
@ -223,6 +224,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
if (frameCount == 0) {
return nil;
}
frames = [NSMutableArray arrayWithCapacity:frameCount];
CGFloat scale = animatedImage.scale;
for (size_t i = 0; i < frameCount; i++) {

View File

@ -331,7 +331,7 @@ static NSString * kSDCGImageDestinationRequestedFileSize = @"kCGImageDestination
if (decodeFirstFrame || count <= 1) {
animatedImage = [self.class createFrameAtIndex:0 source:source scale:scale preserveAspectRatio:preserveAspectRatio thumbnailSize:thumbnailSize forceDecode:NO options:nil];
} else {
NSMutableArray<SDImageFrame *> *frames = [NSMutableArray array];
NSMutableArray<SDImageFrame *> *frames = [NSMutableArray arrayWithCapacity:count];
for (size_t i = 0; i < count; i++) {
UIImage *image = [self.class createFrameAtIndex:i source:source scale:scale preserveAspectRatio:preserveAspectRatio thumbnailSize:thumbnailSize forceDecode:NO options:nil];

View File

@ -85,9 +85,10 @@ inline UIImage * _Nullable SDScaledImageForScaleFactor(CGFloat scale, UIImage *
UIImage *animatedImage;
#if SD_UIKIT || SD_WATCH
// `UIAnimatedImage` images share the same size and scale.
NSMutableArray<UIImage *> *scaledImages = [NSMutableArray array];
NSArray<UIImage *> *images = image.images;
NSMutableArray<UIImage *> *scaledImages = [NSMutableArray arrayWithCapacity:images.count];
for (UIImage *tempImage in image.images) {
for (UIImage *tempImage in images) {
UIImage *tempScaledImage = [[UIImage alloc] initWithCGImage:tempImage.CGImage scale:scale orientation:tempImage.imageOrientation];
[scaledImages addObject:tempScaledImage];
}