Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use dispatch_once to make the newline charset initialisation thread s…

…afe.
  • Loading branch information...
commit 529e14ec50c514c0ab95d3f3ade6107d78bf9b41 1 parent 4556cf8
Tom Davie authored
5 CoreParse/Tokenisation/CPTokeniser.m
@@ -212,10 +212,11 @@ - (void)addToken:(CPToken *)tok toStream:(CPTokenStream *)stream
212 212
213 213 - (void)advanceLineNumber:(NSUInteger *)ln columnNumber:(NSUInteger *)cn withInput:(NSString *)input range:(CFRange)range
214 214 {
215   - if (newlineCharset == nil)
  215 + static dispatch_once_t onceToken;
  216 + dispatch_once(&onceToken, ^
216 217 {
217 218 newlineCharset = (CFCharacterSetRef)[[NSCharacterSet characterSetWithCharactersInString:@"\n\r"] retain];
218   - }
  219 + });
219 220
220 221 CFRange searchRange = range;
221 222 NSUInteger rangeEnd = range.location + range.length;
7 CoreParseTests/CPTestWhiteSpaceIgnoringDelegate.m
@@ -15,13 +15,12 @@ - (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
15 15 return YES;
16 16 }
17 17
18   -- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
  18 +- (void)tokeniser:(CPTokeniser *)tokeniser requestsToken:(CPToken *)token pushedOntoStream:(CPTokenStream *)stream
19 19 {
20   - if ([token isWhiteSpaceToken] || [[token name] isEqualToString:@"Comment"])
  20 + if (![token isWhiteSpaceToken])
21 21 {
22   - return [NSArray array];
  22 + [stream pushToken:token];
23 23 }
24   - return [NSArray arrayWithObject:token];
25 24 }
26 25
27 26 - (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.