I have some efficient methods that recursively creates a tree structure (NSTreeNode) of by looping recursively over a directory structure. The result is displayed in a NSOutlineView. This works well with one exception where I have to non-concurrently update a NSMutableDictionary that holds the structure of the tree. This turns out to be a real bottleneck in my program.
I am wondering if anyone has suggestions for how I can make this method more efficient or avoid the whole method.
-(void) addDictionaryItem:(NSString *) mykey withURL:(NSString *)myurl isDir:(BOOL) myIsDir andLR:(NSString *)LR
{
NSDictionary *mydict=nil;
@synchronized(@"concurrentDictAccess") {
mydict = [self.dict objectForKey:mykey];
}
if ( mydict !=nil) {
NSMutableArray *myarray = [mydict objectForKey:@"myarray"];
NSMutableArray *myarrayIsDir = [mydict objectForKey:@"isdir"];
NSMutableArray *myarrayLR = [mydict objectForKey:@"LR"];
if (![myarray containsObject:myurl]){
[myarray addObject:myurl];
[myarrayLR addObject:LR];
[myarrayIsDir addObject:[NSNumber numberWithBool:myIsDir]];
}
}
else {
NSMutableArray *arrayOfFiles = [NSMutableArray array];
[arrayOfFiles addObject:myurl];
NSMutableArray *arrayIsDir = [NSMutableArray array];
[arrayIsDir addObject:[NSNumber numberWithBool:myIsDir]];
NSMutableArray *arrayOfLR = [NSMutableArray array];
[arrayOfLR addObject:LR];
NSMutableDictionary *attrDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:arrayOfLR, @"LR",
arrayOfFiles, @"myarray", arrayIsDir, @"isdir",
nil];
@synchronized(@"concurrentDictAccess") {
[self.dict setObject:attrDict forKey:mykey];
}
}
}