Skip to content
Browse files

Use dispatch_once to make the newline charset initialisation thread s…

…afe.
  • Loading branch information...
1 parent 4556cf8 commit 529e14ec50c514c0ab95d3f3ade6107d78bf9b41 Tom Davie committed Oct 17, 2012
Showing with 6 additions and 6 deletions.
  1. +3 −2 CoreParse/Tokenisation/CPTokeniser.m
  2. +3 −4 CoreParseTests/CPTestWhiteSpaceIgnoringDelegate.m
View
5 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;
View
7 CoreParseTests/CPTestWhiteSpaceIgnoringDelegate.m
@@ -15,13 +15,12 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
return YES;
}
-- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
+- (void)tokeniser:(CPTokeniser *)tokeniser requestsToken:(CPToken *)token pushedOntoStream:(CPTokenStream *)stream
{
- if ([token isWhiteSpaceToken] || [[token name] isEqualToString:@"Comment"])
+ if (![token isWhiteSpaceToken])
{
- return [NSArray array];
+ [stream pushToken:token];
}
- return [NSArray arrayWithObject:token];
}
- (NSUInteger)tokeniser:(CPTokeniser *)tokeniser didNotFindTokenOnInput:(NSString *)input position:(NSUInteger)position error:(NSString **)errorMessage

0 comments on commit 529e14e

Please sign in to comment.
Something went wrong with that request. Please try again.