mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-18 11:38:53 +00:00
new optimization that strongly improve the lookup time of labels
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
|
||||
#import <NGObjWeb/SoObjects.h>
|
||||
@@ -92,32 +93,59 @@
|
||||
|
||||
- (NSString *) labelForKey: (NSString *) key
|
||||
{
|
||||
NSString *userLanguage, *label;
|
||||
NSString *bundleId, *userLanguage, *label;
|
||||
NSArray *paths;
|
||||
NSBundle *bundle;
|
||||
NSDictionary *strings;
|
||||
SOGoUserDefaults *ud;
|
||||
static NSMutableDictionary *bundlesCache = nil;
|
||||
NSMutableDictionary *languagesCache, *stringsCache;
|
||||
|
||||
if (!bundlesCache)
|
||||
bundlesCache = [NSMutableDictionary new];
|
||||
|
||||
bundle = [NSBundle bundleForClass: [self class]];
|
||||
if (!bundle)
|
||||
bundle = [NSBundle mainBundle];
|
||||
|
||||
bundleId = [bundle executablePath];
|
||||
languagesCache = [bundlesCache objectForKey: bundleId];
|
||||
if (!languagesCache)
|
||||
{
|
||||
languagesCache = [NSMutableDictionary new];
|
||||
[bundlesCache setObject: languagesCache forKey: bundleId];
|
||||
[languagesCache release];
|
||||
}
|
||||
|
||||
ud = [[context activeUser] userDefaults];
|
||||
userLanguage = [ud language];
|
||||
paths = [bundle pathsForResourcesOfType: @"strings"
|
||||
inDirectory: [NSString stringWithFormat: @"%@.lproj",
|
||||
userLanguage]
|
||||
forLocalization: userLanguage];
|
||||
if ([paths count] > 0)
|
||||
stringsCache = [languagesCache objectForKey: userLanguage];
|
||||
if (!stringsCache)
|
||||
{
|
||||
strings = [NSDictionary
|
||||
dictionaryFromStringsFile: [paths objectAtIndex: 0]];
|
||||
label = [strings objectForKey: key];
|
||||
if (!label)
|
||||
label = key;
|
||||
stringsCache = [NSMutableDictionary new];
|
||||
[bundlesCache setObject: stringsCache forKey: userLanguage];
|
||||
[stringsCache release];
|
||||
}
|
||||
|
||||
label = [stringsCache objectForKey: key];
|
||||
if (!label)
|
||||
{
|
||||
paths = [bundle pathsForResourcesOfType: @"strings"
|
||||
inDirectory: [NSString stringWithFormat: @"%@.lproj",
|
||||
userLanguage]
|
||||
forLocalization: userLanguage];
|
||||
if ([paths count] > 0)
|
||||
{
|
||||
strings = [NSDictionary
|
||||
dictionaryFromStringsFile: [paths objectAtIndex: 0]];
|
||||
label = [strings objectForKey: key];
|
||||
if (!label)
|
||||
label = key;
|
||||
}
|
||||
else
|
||||
label = key;
|
||||
[stringsCache setObject: label forKey: key];
|
||||
}
|
||||
else
|
||||
label = key;
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user