Skip to content

Commit

Permalink
Don't cache resizable images
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Puls committed Aug 30, 2013
1 parent b3de4f7 commit 450f17c
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions assetgen/AGCatalogParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ - (void)parseImageSetAtURL:(NSURL *)url;
[implementation appendString:@"}\n"];

} else {
[implementation appendFormat:@" UIImage *image = [[self imageCache] objectForKey:@\"%@\"];\n", name];
[implementation appendString:@" if (image) {\n"];
[implementation appendString:@" return image;\n"];
[implementation appendString:@" }\n\n"];
[implementation appendString:@" UIImage *image = nil;\n\n"];

for (NSDictionary *variant in variants) {
if (!variant[@"filename"]) {
Expand Down Expand Up @@ -174,7 +171,6 @@ - (void)parseImageSetAtURL:(NSURL *)url;
[implementation appendString:@"\n"];
}

[implementation appendFormat:@" [[self imageCache] setObject:image forKey:@\"%@\"];\n", name];
[implementation appendString:@" return image;\n"];
[implementation appendString:@"}\n"];
}
Expand All @@ -184,23 +180,6 @@ - (void)parseImageSetAtURL:(NSURL *)url;
}
}

- (NSString *)cacheMethodContents;
{
NSMutableString *contents = [NSMutableString string];

[contents appendString:@"+ (NSCache *)imageCache;\n"];
[contents appendString:@"{\n"];
[contents appendString:@" static dispatch_once_t onceToken;\n"];
[contents appendString:@" static NSCache *imageCache = nil;\n"];
[contents appendString:@" dispatch_once(&onceToken, ^{\n"];
[contents appendString:@" imageCache = [NSCache new];\n"];
[contents appendString:@" });\n"];
[contents appendString:@" return imageCache;\n"];
[contents appendString:@"}\n"];

return contents;
}

- (void)outputCode;
{
NSURL *currentDirectory = [NSURL fileURLWithPath:[[NSFileManager new] currentDirectoryPath]];
Expand All @@ -224,7 +203,7 @@ - (void)outputCode;
[interface writeToURL:interfaceURL atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}

NSString *implementation = [NSString stringWithFormat:@"//\n// This file is generated from %@.xcassets by objc-assetgen.\n// Please do not edit.\n//\n\n#import \"%@\"\n\n@implementation %@\n\n%@\n%@\n\n@end\n", self.catalogName, classNameH, className, self.cacheMethodContents, [self.implementationContents componentsJoinedByString:@"\n"]];
NSString *implementation = [NSString stringWithFormat:@"//\n// This file is generated from %@.xcassets by objc-assetgen.\n// Please do not edit.\n//\n\n#import \"%@\"\n\n@implementation %@\n\n%@\n\n@end\n", self.catalogName, classNameH, className, [self.implementationContents componentsJoinedByString:@"\n"]];

if (![implementation isEqualToString:[NSString stringWithContentsOfURL:implementationURL encoding:NSUTF8StringEncoding error:NULL]]) {
[implementation writeToURL:implementationURL atomically:YES encoding:NSUTF8StringEncoding error:NULL];
Expand Down

0 comments on commit 450f17c

Please sign in to comment.