Fixes possible issues with wrong initial capacities

This commit is contained in:
michael starke
2014-07-31 13:08:28 +02:00
parent d7741451fd
commit 95bb918b6f
3 changed files with 3 additions and 3 deletions

View File

@@ -96,7 +96,7 @@
if(![context isValid]) { if(![context isValid]) {
return nil; return nil;
} }
NSUInteger reserverd = [context.normalizedCommand length] / 4; NSUInteger reserverd = MAX(1,[context.normalizedCommand length] / 4);
NSMutableArray *commands = [[NSMutableArray alloc] initWithCapacity:reserverd]; NSMutableArray *commands = [[NSMutableArray alloc] initWithCapacity:reserverd];
NSMutableArray __block *commandRanges = [[NSMutableArray alloc] initWithCapacity:reserverd]; NSMutableArray __block *commandRanges = [[NSMutableArray alloc] initWithCapacity:reserverd];
NSRegularExpression *commandRegExp = [[NSRegularExpression alloc] initWithPattern:@"\\{[^\\}]+\\}" options:NSRegularExpressionCaseInsensitive error:0]; NSRegularExpression *commandRegExp = [[NSRegularExpression alloc] initWithPattern:@"\\{[^\\}]+\\}" options:NSRegularExpressionCaseInsensitive error:0];

View File

@@ -35,7 +35,7 @@
return nil; return nil;
} }
NSArray *autotypeEntries = [self.root autotypeableChildEntries]; NSArray *autotypeEntries = [self.root autotypeableChildEntries];
NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:ceil([autotypeEntries count] / 4.0)]; NSMutableArray *contexts = [[NSMutableArray alloc] initWithCapacity:MAX(1,ceil([autotypeEntries count] / 4.0))];
for(KPKEntry *entry in autotypeEntries) { for(KPKEntry *entry in autotypeEntries) {
/* Test for title */ /* Test for title */
NSRange titleRange = [entry.title rangeOfString:windowTitle options:NSCaseInsensitiveSearch]; NSRange titleRange = [entry.title rangeOfString:windowTitle options:NSCaseInsensitiveSearch];