Caching Gregorian NSCalendar for performance.

This was taking about 30% of the time unzipping on an iPhone 5.
This commit is contained in:
Rogers, Christopher
2013-07-12 17:28:18 +09:00
parent f9136dd744
commit 84c8171151
+6 -2
View File
@@ -495,7 +495,12 @@
static const UInt32 kMinuteMask = 0x7E0;
static const UInt32 kSecondMask = 0x1F;
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
static NSCalendar *gregorian
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
});
NSDateComponents *components = [[NSDateComponents alloc] init];
NSAssert(0xFFFFFFFF == (kYearMask | kMonthMask | kDayMask | kHourMask | kMinuteMask | kSecondMask), @"[SSZipArchive] MSDOS date masks don't add up");
@@ -510,7 +515,6 @@
NSDate *date = [NSDate dateWithTimeInterval:0 sinceDate:[gregorian dateFromComponents:components]];
#if !__has_feature(objc_arc)
[gregorian release];
[components release];
#endif