mirror of
https://github.com/textmate/textmate.git
synced 2026-01-21 20:57:54 -05:00
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).
This commit is contained in:
@@ -3,7 +3,23 @@
|
||||
@implementation NSImage (ImageFromBundle)
|
||||
+ (NSImage*)imageNamed:(NSString*)aName inSameBundleAsClass:(id)aClass
|
||||
{
|
||||
return [[NSBundle bundleForClass:aClass] imageForResource:aName];
|
||||
if(!aName)
|
||||
return nil;
|
||||
|
||||
NSBundle* bundle = [NSBundle bundleForClass:aClass];
|
||||
NSString* name = [NSString stringWithFormat:@"%@.%@", [bundle bundleIdentifier], aName];
|
||||
|
||||
static NSMutableDictionary* cache = [NSMutableDictionary new];
|
||||
if(NSImage* res = [cache objectForKey:name])
|
||||
return res;
|
||||
|
||||
if(NSImage* image = [[NSBundle bundleForClass:aClass] imageForResource:aName])
|
||||
{
|
||||
[cache setObject:image forKey:name];
|
||||
return image;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
// ===================================================
|
||||
|
||||
Reference in New Issue
Block a user