From bcdea2adb44989baf591bc5dd8f5d56d04f2c98c Mon Sep 17 00:00:00 2001 From: Boris Suvorov Date: Mon, 6 Jul 2015 19:20:50 -0700 Subject: [PATCH] Cache nonParameterCharacterSet to help minimize memory footprint in multithreaded apps using SOCKit Relevant github.com pull request into SOCKit is located here: https://github.com/NimbusKit/sockit/pull/26 --- src/SOCKit.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SOCKit.m b/src/SOCKit.m index 33fbf11..0c7bafb 100644 --- a/src/SOCKit.m +++ b/src/SOCKit.m @@ -72,11 +72,13 @@ - (id)copyWithZone:(NSZone *)zone { - (NSCharacterSet *)nonParameterCharacterSet { static NSCharacterSet* staticNonParameterCharacterSet = nil; - if (staticNonParameterCharacterSet == nil) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ NSMutableCharacterSet* parameterCharacterSet = [NSMutableCharacterSet alphanumericCharacterSet]; [parameterCharacterSet addCharactersInString:@".@_"]; staticNonParameterCharacterSet = [parameterCharacterSet invertedSet]; - } + }); + return staticNonParameterCharacterSet; }