Skip to content

Commit

Permalink
Make searches with many matches exponentially faster
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanj committed Nov 3, 2014
1 parent b1f169a commit 22bec9d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Classes/Controllers/PBHistorySearchController.m
Original file line number Diff line number Diff line change
Expand Up @@ -438,23 +438,25 @@ - (void)parseBackgroundSearchResults:(NSNotification *)notification
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:[notification object]];
backgroundSearchTask = nil;

NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
NSData *data = [[notification userInfo] valueForKey:NSFileHandleNotificationDataItem];

NSString *resultsString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSArray *resultsArray = [resultsString componentsSeparatedByString:@"\n"];

NSMutableSet *matches = [NSMutableSet new];
for (NSString *resultSHA in resultsArray) {
NSUInteger index = 0;
for (PBGitCommit *commit in [commitController arrangedObjects]) {
if ([resultSHA isEqualToString:commit.sha.SHA]) {
[indexes addIndex:index];
break;
}
index++;
GTOID *resultOID = [GTOID oidWithSHA:resultSHA];
if (resultOID) {
[matches addObject:resultOID];
}
}

NSArray *arrangedObjects = [commitController arrangedObjects];
NSIndexSet *indexes = [arrangedObjects indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
PBGitCommit *commit = obj;
return [matches containsObject:commit.sha];
}];

results = indexes;
[self clearProgressIndicator];
[self updateSelectedResult];
Expand Down

0 comments on commit 22bec9d

Please sign in to comment.