mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-15 13:32:26 +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,
|
MPIconCamera,
|
||||||
MPIconRemote,
|
MPIconRemote,
|
||||||
MPIconKeys,
|
MPIconKeys,
|
||||||
MPIconScanner = 15,
|
MPIconBattery,
|
||||||
|
MPIconScanner,
|
||||||
MPIconBrowser,
|
MPIconBrowser,
|
||||||
MPIconCDRom,
|
MPIconCDRom,
|
||||||
MPIconDisplay,
|
MPIconDisplay,
|
||||||
MPIconEmail,
|
MPIconEmail,
|
||||||
MPIconMisc,
|
MPIconMisc,
|
||||||
MPIconFileSave = 26,
|
MPIconFileSave = 26,
|
||||||
|
MPIconTerminal = 30,
|
||||||
|
MPIconPrint = 31,
|
||||||
MPIconTrash = 43,
|
MPIconTrash = 43,
|
||||||
MPIconFolder = 48,
|
MPIconFolder = 48,
|
||||||
MPIconPhone = 68,
|
MPIconPhone = 68,
|
||||||
|
|||||||
@@ -24,20 +24,28 @@ static NSDictionary *icons;
|
|||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)databaseIcons {
|
+ (NSArray *)databaseIcons {
|
||||||
|
static NSArray *icons;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
NSDictionary *imageNames = [MPIconHelper availableIconNames];
|
NSDictionary *imageNames = [MPIconHelper availableIconNames];
|
||||||
NSMutableArray *icons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]];
|
NSMutableArray *mutableIcons = [[NSMutableArray alloc] initWithCapacity:[imageNames count]];
|
||||||
for(NSNumber *iconNumber in [imageNames allKeys]) {
|
for(NSNumber *iconNumber in [imageNames allKeys]) {
|
||||||
if([iconNumber integerValue] > MPCustomIconTypeBegin) {
|
if([iconNumber integerValue] > MPCustomIconTypeBegin) {
|
||||||
continue; // Skip all non-db Keys
|
continue; // Skip all non-db Keys
|
||||||
}
|
}
|
||||||
MPIconType iconType = (MPIconType)[iconNumber integerValue];
|
MPIconType iconType = (MPIconType)[iconNumber integerValue];
|
||||||
[icons addObject:[MPIconHelper icon:iconType]];
|
[mutableIcons addObject:[MPIconHelper icon:iconType]];
|
||||||
}
|
}
|
||||||
|
icons = mutableIcons;
|
||||||
|
});
|
||||||
return icons;
|
return icons;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSDictionary *)availableIconNames {
|
+ (NSDictionary *)availableIconNames {
|
||||||
NSDictionary *imageNames = @{
|
static NSDictionary *imageNames;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
imageNames = @{
|
||||||
@(MPIconPassword): @"00_PasswordTemplate",
|
@(MPIconPassword): @"00_PasswordTemplate",
|
||||||
@(MPIconPackageNetwork): @"01_PackageNetworkTemplate",
|
@(MPIconPackageNetwork): @"01_PackageNetworkTemplate",
|
||||||
@(MPIconWarning): @"02_MessageBoxWarningTemplate",
|
@(MPIconWarning): @"02_MessageBoxWarningTemplate",
|
||||||
@@ -52,7 +60,7 @@ static NSDictionary *icons;
|
|||||||
@(MPIconCamera): @"11_CameraTemplate",
|
@(MPIconCamera): @"11_CameraTemplate",
|
||||||
@(MPIconRemote): @"12_RemoteTemplate",
|
@(MPIconRemote): @"12_RemoteTemplate",
|
||||||
@(MPIconKeys): @"13_KeysTemplate",
|
@(MPIconKeys): @"13_KeysTemplate",
|
||||||
|
@(MPIconBattery): @"14_BatteryTemplate",
|
||||||
@(MPIconScanner): @"15_ScannerTemplate",
|
@(MPIconScanner): @"15_ScannerTemplate",
|
||||||
@(MPIconBrowser): @"16_BrowserTemplate",
|
@(MPIconBrowser): @"16_BrowserTemplate",
|
||||||
@(MPIconCDRom): @"17_CDRomTemplate",
|
@(MPIconCDRom): @"17_CDRomTemplate",
|
||||||
@@ -62,6 +70,9 @@ static NSDictionary *icons;
|
|||||||
|
|
||||||
@(MPIconFileSave): @"26_FileSaveTemplate",
|
@(MPIconFileSave): @"26_FileSaveTemplate",
|
||||||
|
|
||||||
|
@(MPIconTerminal) : @"30_TerminalTemplate",
|
||||||
|
@(MPIconPrint) : @"31_PrintTemplate",
|
||||||
|
|
||||||
@(MPIconTrash): @"43_TrashTemplate",
|
@(MPIconTrash): @"43_TrashTemplate",
|
||||||
|
|
||||||
@(MPIconFolder): @"48_FolderTemplate",
|
@(MPIconFolder): @"48_FolderTemplate",
|
||||||
@@ -75,6 +86,7 @@ static NSDictionary *icons;
|
|||||||
@(MPIconAddEntry): @"addEntryTemplate",
|
@(MPIconAddEntry): @"addEntryTemplate",
|
||||||
@(MPIconContextTriangle): @"contextTriangleTemplate"
|
@(MPIconContextTriangle): @"contextTriangleTemplate"
|
||||||
};
|
};
|
||||||
|
});
|
||||||
return imageNames;
|
return imageNames;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user