From 332441cbe543090a096c55149efd2bd711c277e3 Mon Sep 17 00:00:00 2001 From: Boris Suvorov Date: Mon, 6 Jul 2015 18:41:23 -0700 Subject: [PATCH] Cache nonParameterCharacterSet in SOCKit.m to avoid memory spikes --- src/SOCKit.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/SOCKit.m b/src/SOCKit.m index 2cd36d8..33fbf11 100644 --- a/src/SOCKit.m +++ b/src/SOCKit.m @@ -71,10 +71,13 @@ - (id)copyWithZone:(NSZone *)zone { #pragma mark - Pattern Compilation - (NSCharacterSet *)nonParameterCharacterSet { - NSMutableCharacterSet* parameterCharacterSet = [NSMutableCharacterSet alphanumericCharacterSet]; - [parameterCharacterSet addCharactersInString:@".@_"]; - NSCharacterSet* nonParameterCharacterSet = [parameterCharacterSet invertedSet]; - return nonParameterCharacterSet; + static NSCharacterSet* staticNonParameterCharacterSet = nil; + if (staticNonParameterCharacterSet == nil) { + NSMutableCharacterSet* parameterCharacterSet = [NSMutableCharacterSet alphanumericCharacterSet]; + [parameterCharacterSet addCharactersInString:@".@_"]; + staticNonParameterCharacterSet = [parameterCharacterSet invertedSet]; + } + return staticNonParameterCharacterSet; } - (void)_compilePattern {