From 84c81711518792fd86909b413ccda9548e325c11 Mon Sep 17 00:00:00 2001 From: "Rogers, Christopher" Date: Fri, 12 Jul 2013 17:28:18 +0900 Subject: [PATCH] Caching Gregorian NSCalendar for performance. This was taking about 30% of the time unzipping on an iPhone 5. --- SSZipArchive.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SSZipArchive.m b/SSZipArchive.m index 67c89c3..0890eaa 100644 --- a/SSZipArchive.m +++ b/SSZipArchive.m @@ -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