Skip to content

Commit c53c1af

Browse files
committed
Minor changes for maximum speed.
1 parent 17ef7be commit c53c1af

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

Core/Source/DTLocalizableStringScanner.m

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ - (void)main
192192
}
193193
}
194194

195-
#define IS_WHITESPACE(_c) ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:(_c)])
195+
196+
#define IS_WHITESPACE(_c) (_c == ' ' || _c == '\t' || _c == 0xA || _c == 0xB || _c == 0xC || _c == 0xD || _c == 0x85)
196197

197198
- (void)_scanWhitespace
198199
{
199-
while (IS_WHITESPACE(_characters[_currentIndex]) && _currentIndex < _stringLength)
200+
while (IS_WHITESPACE(_characters[_currentIndex]) && _currentIndex < _charactersRange.length)
200201
{
201202
_currentIndex++;
202203
}
@@ -305,7 +306,6 @@ - (NSString *)_scanParameter
305306
}
306307

307308
- (BOOL)_processMacroAtRange:(NSRange)range
308-
NSMutableArray *parameters = [[NSMutableArray alloc] initWithCapacity:10];
309309
{
310310
if (_characters == nil) {
311311
_charactersRange = NSMakeRange(range.location, [_charactersAsString length] - range.location);
@@ -314,6 +314,7 @@ - (BOOL)_processMacroAtRange:(NSRange)range
314314
}
315315
_currentIndex = range.location + range.length - _charactersRange.location;
316316

317+
NSMutableArray *parameters = [[NSMutableArray alloc] initWithCapacity:3];
317318

318319
// skip any whitespace between here and the (
319320
[self _scanWhitespace];
@@ -366,29 +367,43 @@ - (BOOL)_processMacroAtRange:(NSRange)range
366367
}
367368
}
368369

369-
NSArray *expectedParameters = [_validMacros objectForKey:macroName];
370-
if ([expectedParameters count] == [parameters count])
371-
{
372-
// hooray, we successfully scanned!
373-
374-
DTLocalizableStringEntry *entry = [[DTLocalizableStringEntry alloc] init];
375-
for (NSUInteger i = 0; i < [parameters count]; ++i)
370+
if ([parameters count] > 0) {
371+
NSString *macroName = [_charactersAsString substringWithRange:range];
372+
NSArray *expectedParameters = [_validMacros objectForKey:macroName];
373+
if ([expectedParameters count] == [parameters count])
376374
{
377-
NSString *property = [expectedParameters objectAtIndex:i];
378-
NSString *value = [parameters objectAtIndex:i];
379-
[entry setValue:value forKey:property];
380-
}
381-
382-
if (_entryFoundCallback)
375+
// hooray, we successfully scanned!
376+
377+
DTLocalizableStringEntry *entry = [[DTLocalizableStringEntry alloc] init];
378+
for (NSUInteger i = 0; i < [parameters count]; ++i)
379+
{
380+
NSString *property = [expectedParameters objectAtIndex:i];
381+
NSString *value = [parameters objectAtIndex:i];
382+
383+
if ([property isEqualToString:@"rawKey"]) {
384+
entry.rawKey = value;
385+
} else if ([property isEqualToString:@"comment"]) {
386+
[entry setComment:value];
387+
} else if ([property isEqualToString:@"tableName"]) {
388+
entry.tableName = value;
389+
} else if ([property isEqualToString:@"bundle"]) {
390+
entry.bundle = value;
391+
} else {
392+
[entry setValue:value forKey:property];
393+
}
394+
}
395+
396+
if (_entryFoundCallback)
397+
{
398+
_entryFoundCallback(entry);
399+
}
400+
401+
return YES;
402+
}
403+
else
383404
{
384-
_entryFoundCallback(entry);
405+
NSLog(@"mismatch of parameters for %@ macro", macroName);
385406
}
386-
387-
return YES;
388-
}
389-
else
390-
{
391-
NSLog(@"mismatch of parameters for %@ macro", macroName);
392407
}
393408

394409
return NO;

0 commit comments

Comments
 (0)