mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 12:52:21 +00:00
Optimized IconHelper to only create internal structures once, not all the time.
This commit is contained in:
@@ -27,13 +27,16 @@ typedef NS_ENUM(NSUInteger, MPIconType) {
|
||||
MPIconCamera,
|
||||
MPIconRemote,
|
||||
MPIconKeys,
|
||||
MPIconScanner = 15,
|
||||
MPIconBattery,
|
||||
MPIconScanner,
|
||||
MPIconBrowser,
|
||||
MPIconCDRom,
|
||||
MPIconDisplay,
|
||||
MPIconEmail,
|
||||
MPIconMisc,
|
||||
MPIconFileSave = 26,
|
||||
MPIconTerminal = 30,
|
||||
MPIconPrint = 31,
|
||||
MPIconTrash = 43,
|
||||
MPIconFolder = 48,
|
||||
MPIconPhone = 68,
|
||||
|
||||
@@ -14,7 +14,7 @@ static NSDictionary *icons;
|
||||
|
||||
+ (NSImage *)icon:(MPIconType)type {
|
||||
if(!icons) {
|
||||
icons = [MPIconHelper availableIconNames];
|
||||
icons = [MPIconHelper availableIconNames];
|
||||
}
|
||||
if([[icons allKeys] containsObject:@(type)]) {
|
||||
NSString *imageName = icons[@(type)];
|
||||
@@ -24,57 +24,69 @@ static NSDictionary *icons;
|
||||
}
|
||||
|
||||
+ (NSArray *)databaseIcons {
|
||||
NSDictionary *imageNames = [MPIconHelper availableIconNames];
|
||||
NSMutableArray *icons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]];
|
||||
for(NSNumber *iconNumber in [imageNames allKeys]) {
|
||||
if([iconNumber integerValue] > MPCustomIconTypeBegin) {
|
||||
continue; // Skip all non-db Keys
|
||||
static NSArray *icons;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
NSDictionary *imageNames = [MPIconHelper availableIconNames];
|
||||
NSMutableArray *mutableIcons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]];
|
||||
for(NSNumber *iconNumber in [imageNames allKeys]) {
|
||||
if([iconNumber integerValue] > MPCustomIconTypeBegin) {
|
||||
continue; // Skip all non-db Keys
|
||||
}
|
||||
MPIconType iconType = (MPIconType)[iconNumber integerValue];
|
||||
[mutableIcons addObject:[MPIconHelper icon:iconType]];
|
||||
}
|
||||
MPIconType iconType = (MPIconType)[iconNumber integerValue];
|
||||
[icons addObject:[MPIconHelper icon:iconType]];
|
||||
}
|
||||
icons = mutableIcons;
|
||||
});
|
||||
return icons;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)availableIconNames {
|
||||
NSDictionary *imageNames = @{
|
||||
@(MPIconPassword): @"00_PasswordTemplate",
|
||||
@(MPIconPackageNetwork): @"01_PackageNetworkTemplate",
|
||||
@(MPIconWarning): @"02_MessageBoxWarningTemplate",
|
||||
@(MPIconServer): @"03_ServerTemplate",
|
||||
@(MPIconKlipper): @"04_KlipperTemplate",
|
||||
@(MPIconLanguages): @"05_LanguagesTemplate",
|
||||
@(MPIconBlockDevice): @"06_BlockDeviceTemplate",
|
||||
@(MPIconNotepad): @"07_NotepadTemplate",
|
||||
@(MPIconSocket): @"08_SocketTemplate",
|
||||
@(MPIconIdentity): @"09_IdentityTemplate",
|
||||
@(MPIconContact): @"10_ContactTemplate",
|
||||
@(MPIconCamera): @"11_CameraTemplate",
|
||||
@(MPIconRemote): @"12_RemoteTemplate",
|
||||
@(MPIconKeys): @"13_KeysTemplate",
|
||||
|
||||
@(MPIconScanner): @"15_ScannerTemplate",
|
||||
@(MPIconBrowser): @"16_BrowserTemplate",
|
||||
@(MPIconCDRom): @"17_CDRomTemplate",
|
||||
@(MPIconDisplay): @"18_DisplayTemplate",
|
||||
@(MPIconEmail): @"19_EmailTemplate",
|
||||
@(MPIconMisc): @"20_MiscTemplate",
|
||||
|
||||
@(MPIconFileSave): @"26_FileSaveTemplate",
|
||||
|
||||
@(MPIconTrash): @"43_TrashTemplate",
|
||||
|
||||
@(MPIconFolder): @"48_FolderTemplate",
|
||||
|
||||
@(MPIconPhone): @"68_PhoneTemplate",
|
||||
|
||||
@(MPIconInfo): @"99_InfoTemplate",
|
||||
@(MPIconAddFolder): @"99_AddFolderTemplate",
|
||||
@(MPIconHardDisk): @"99_HarddiskTemplate",
|
||||
@(MPIconCreated): @"99_CreatedTemplate",
|
||||
@(MPIconAddEntry): @"addEntryTemplate",
|
||||
@(MPIconContextTriangle): @"contextTriangleTemplate"
|
||||
};
|
||||
static NSDictionary *imageNames;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
imageNames = @{
|
||||
@(MPIconPassword): @"00_PasswordTemplate",
|
||||
@(MPIconPackageNetwork): @"01_PackageNetworkTemplate",
|
||||
@(MPIconWarning): @"02_MessageBoxWarningTemplate",
|
||||
@(MPIconServer): @"03_ServerTemplate",
|
||||
@(MPIconKlipper): @"04_KlipperTemplate",
|
||||
@(MPIconLanguages): @"05_LanguagesTemplate",
|
||||
@(MPIconBlockDevice): @"06_BlockDeviceTemplate",
|
||||
@(MPIconNotepad): @"07_NotepadTemplate",
|
||||
@(MPIconSocket): @"08_SocketTemplate",
|
||||
@(MPIconIdentity): @"09_IdentityTemplate",
|
||||
@(MPIconContact): @"10_ContactTemplate",
|
||||
@(MPIconCamera): @"11_CameraTemplate",
|
||||
@(MPIconRemote): @"12_RemoteTemplate",
|
||||
@(MPIconKeys): @"13_KeysTemplate",
|
||||
@(MPIconBattery): @"14_BatteryTemplate",
|
||||
@(MPIconScanner): @"15_ScannerTemplate",
|
||||
@(MPIconBrowser): @"16_BrowserTemplate",
|
||||
@(MPIconCDRom): @"17_CDRomTemplate",
|
||||
@(MPIconDisplay): @"18_DisplayTemplate",
|
||||
@(MPIconEmail): @"19_EmailTemplate",
|
||||
@(MPIconMisc): @"20_MiscTemplate",
|
||||
|
||||
@(MPIconFileSave): @"26_FileSaveTemplate",
|
||||
|
||||
@(MPIconTerminal) : @"30_TerminalTemplate",
|
||||
@(MPIconPrint) : @"31_PrintTemplate",
|
||||
|
||||
@(MPIconTrash): @"43_TrashTemplate",
|
||||
|
||||
@(MPIconFolder): @"48_FolderTemplate",
|
||||
|
||||
@(MPIconPhone): @"68_PhoneTemplate",
|
||||
|
||||
@(MPIconInfo): @"99_InfoTemplate",
|
||||
@(MPIconAddFolder): @"99_AddFolderTemplate",
|
||||
@(MPIconHardDisk): @"99_HarddiskTemplate",
|
||||
@(MPIconCreated): @"99_CreatedTemplate",
|
||||
@(MPIconAddEntry): @"addEntryTemplate",
|
||||
@(MPIconContextTriangle): @"contextTriangleTemplate"
|
||||
};
|
||||
});
|
||||
return imageNames;
|
||||
}
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user