TextMate is a graphical text editor for OS X 10.7+
Revision | 9366a1ec508bb2f45604d5212c0709f88caeca2e (tree) |
---|---|
Zeit | 2012-08-19 21:44:57 |
Autor | Allan Odgaard <git@abet...> |
Commiter | Allan Odgaard |
Cache image resources
This was also done prior to commit 806cb44. I just assumed that now that we are back using the system’s named image stuff, we would benefit from their cache, but clearly we are not (especially file browser seemed sluggish because of (re)loading the file type images).
@@ -3,7 +3,23 @@ | ||
3 | 3 | @implementation NSImage (ImageFromBundle) |
4 | 4 | + (NSImage*)imageNamed:(NSString*)aName inSameBundleAsClass:(id)aClass |
5 | 5 | { |
6 | - return [[NSBundle bundleForClass:aClass] imageForResource:aName]; | |
6 | + if(!aName) | |
7 | + return nil; | |
8 | + | |
9 | + NSBundle* bundle = [NSBundle bundleForClass:aClass]; | |
10 | + NSString* name = [NSString stringWithFormat:@"%@.%@", [bundle bundleIdentifier], aName]; | |
11 | + | |
12 | + static NSMutableDictionary* cache = [NSMutableDictionary new]; | |
13 | + if(NSImage* res = [cache objectForKey:name]) | |
14 | + return res; | |
15 | + | |
16 | + if(NSImage* image = [[NSBundle bundleForClass:aClass] imageForResource:aName]) | |
17 | + { | |
18 | + [cache setObject:image forKey:name]; | |
19 | + return image; | |
20 | + } | |
21 | + | |
22 | + return nil; | |
7 | 23 | } |
8 | 24 | |
9 | 25 | // =================================================== |