adium 3180:6583a9ec00ef: Cache NSDateFormatters in WKMV.
commits at adium.im
commits at adium.im
Thu Apr 29 04:46:42 UTC 2010
details: http://hg.adium.im/adium/rev/6583a9ec00ef
revision: 3180:6583a9ec00ef
author: Colin Barrett <colin at springsandstruts.com>
date: Wed Apr 28 21:45:02 2010 -0700
Cache NSDateFormatters in WKMV.
Still more perf work to do here. Testcase is to join 8 IRC channels with 100 lines of history each.
diffs (79 lines):
diff -r f3768d0d65a2 -r 6583a9ec00ef Plugins/WebKit Message View/AIWebkitMessageViewStyle.h
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Tue Apr 27 20:31:08 2010 -0700
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.h Wed Apr 28 21:45:02 2010 -0700
@@ -124,8 +124,8 @@
NSColor *customBackgroundColor;
NSImage *userIconMask;
- //icon path caches
NSMutableDictionary *statusIconPathCache;
+ NSMutableDictionary *timeFormatterCache;
}
/*!
diff -r f3768d0d65a2 -r 6583a9ec00ef Plugins/WebKit Message View/AIWebkitMessageViewStyle.m
--- a/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Tue Apr 27 20:31:08 2010 -0700
+++ b/Plugins/WebKit Message View/AIWebkitMessageViewStyle.m Wed Apr 28 21:45:02 2010 -0700
@@ -236,7 +236,10 @@
[self releaseResources];
[timeStampFormatter release];
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver: self];
+
[statusIconPathCache release];
+ [timeFormatterCache release];
self.activeVariant = nil;
@@ -323,6 +326,10 @@
}
}
+- (void) flushTimeFormatterCache:(id)dummy {
+ [timeFormatterCache removeAllObjects];
+}
+
@synthesize allowTextBackgrounds, customBackgroundType, customBackgroundColor, showIncomingMessageColors=showIncomingColors, showIncomingMessageFonts=showIncomingFonts, customBackgroundPath, nameFormat, useCustomNameFormat, showHeader, showUserIcons;
//Templates ------------------------------------------------------------------------------------------------------------
@@ -815,23 +822,30 @@
endRange = [inString rangeOfString:@"}%" options:NSLiteralSearch range:NSMakeRange(NSMaxRange(range), [inString length] - NSMaxRange(range))];
if (endRange.location != NSNotFound && endRange.location > NSMaxRange(range)) {
if (date) {
+ if (!timeFormatterCache) {
+ timeFormatterCache = [[NSMutableDictionary alloc] init];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(flushTimeFormatterCache:) name:@"AppleDatePreferencesChangedNotification" object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(flushTimeFormatterCache:) name:@"AppleTimePreferencesChangedNotification" object:nil];
+ }
NSString *timeFormat = [inString substringWithRange:NSMakeRange(NSMaxRange(range), (endRange.location - NSMaxRange(range)))];
- NSDateFormatter *dateFormatter;
- if ([timeFormat rangeOfString:@"%"].location != NSNotFound) {
- /* Support strftime-style format strings, which old message styles may use */
- dateFormatter = [[NSDateFormatter alloc] initWithDateFormat:timeFormat allowNaturalLanguage:NO];
- } else {
- dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
- [dateFormatter setDateFormat:timeFormat];
+ NSDateFormatter *dateFormatter = [timeFormatterCache objectForKey:timeFormat];
+ if (!dateFormatter) {
+ if ([timeFormat rangeOfString:@"%"].location != NSNotFound) {
+ /* Support strftime-style format strings, which old message styles may use */
+ dateFormatter = [[NSDateFormatter alloc] initWithDateFormat:timeFormat allowNaturalLanguage:NO];
+ } else {
+ dateFormatter = [[NSDateFormatter alloc] init];
+ [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
+ [dateFormatter setDateFormat:timeFormat];
+ }
+ [timeFormatterCache setObject:dateFormatter forKey:timeFormat];
+ [dateFormatter release];
}
[inString safeReplaceCharactersInRange:NSUnionRange(range, endRange)
withString:[dateFormatter stringFromDate:date]];
- [dateFormatter release];
-
} else
[inString deleteCharactersInRange:NSUnionRange(range, endRange)];
More information about the commits
mailing list