Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
/ sockit Public archive
forked from NimbusKit/sockit

Commit

Permalink
Cache nonParameterCharacterSet in SOCKit.m to avoid memory spikes in …
Browse files Browse the repository at this point in the history
…multithreaded environments

Relevant github.com pull request into SOCKit is located here: NimbusKit#26
  • Loading branch information
Boris Suvorov committed Jul 7, 2015
1 parent 90937fd commit 2cac171
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/SOCKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ - (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;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSMutableCharacterSet* parameterCharacterSet = [NSMutableCharacterSet alphanumericCharacterSet];
[parameterCharacterSet addCharactersInString:@".@_"];
staticNonParameterCharacterSet = [parameterCharacterSet invertedSet];
});

return staticNonParameterCharacterSet;
}

- (void)_compilePattern {
Expand Down

0 comments on commit 2cac171

Please sign in to comment.