From bc3026a13ffe4ac47d6d76db79eb7cb7abdf020b Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 28 Jun 2012 12:29:01 +0000 Subject: [PATCH] only create the number formatter for formatting integers once --- macosx/NSStringAdditions.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/macosx/NSStringAdditions.m b/macosx/NSStringAdditions.m index fbbf12726..baeb1915c 100644 --- a/macosx/NSStringAdditions.m +++ b/macosx/NSStringAdditions.m @@ -48,11 +48,16 @@ return [self stringByAppendingString: [NSString ellipsis]]; } +#warning use localizedStringWithFormat: directly in roardacted + (NSString *) formattedUInteger: (NSUInteger) value { - NSNumberFormatter * numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; - [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; - [numberFormatter setMaximumFractionDigits: 0]; + static NSNumberFormatter * numberFormatter; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + numberFormatter = [[NSNumberFormatter alloc] init]; + [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; + [numberFormatter setMaximumFractionDigits: 0]; + }); return [numberFormatter stringFromNumber: [NSNumber numberWithUnsignedInteger: value]]; }