Permalink
Browse files

Use dispatch_once to make the newline charset initialisation thread s…

…afe.
  • Loading branch information...
1 parent 4556cf8 commit 000c118bd425e3719b362b70451b3cc97750b513 Tom Davie committed Oct 17, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 CoreParse/Tokenisation/CPTokeniser.m
@@ -212,10 +212,11 @@ - (void)addToken:(CPToken *)tok toStream:(CPTokenStream *)stream
- (void)advanceLineNumber:(NSUInteger *)ln columnNumber:(NSUInteger *)cn withInput:(NSString *)input range:(CFRange)range
{
- if (newlineCharset == nil)
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^
{
newlineCharset = (CFCharacterSetRef)[[NSCharacterSet characterSetWithCharactersInString:@"\n\r"] retain];
- }
+ });
CFRange searchRange = range;
NSUInteger rangeEnd = range.location + range.length;

0 comments on commit 000c118

Please sign in to comment.