Optimize rev-list parsing

This uses the C fgets() over the weird readLine implementation I found.
It speeds up the rev-parsing significantly: we went from ~4.5 seconds
on the git.git repo to ~0.95 seconds. And that's with the secret new date
parsing!
This commit is contained in:
Pieter de Bie
2008-06-17 15:04:49 +02:00
parent aa3f720129
commit 39797876fe
5 changed files with 1445 additions and 1354 deletions
+1 -3
View File
@@ -224,9 +224,7 @@
{
if (![[aTableColumn identifier] isEqualToString:@"subject"])
return;
NSLog(@"Doing cell at index: %i", rowIndex);
NSNumber* n = [NSNumber numberWithInt:(rowIndex % 2)];
[aCell setCommit:n];
+1415 -1341
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -15,6 +15,7 @@
NSString* subject;
NSString* author;
NSString* details;
NSDate* date;
PBGitRepository* repository;
}
@@ -23,6 +24,8 @@
@property (copy) NSString* sha;
@property (copy) NSString* subject;
@property (copy) NSString* author;
@property (copy) NSDate* date;
@property (readonly) NSString* dateString;
@property (readonly) NSString* details;
@property (readonly) PBGitTree* tree;
+8 -1
View File
@@ -11,7 +11,14 @@
@implementation PBGitCommit
@synthesize sha, repository, subject, author;
@synthesize sha, repository, subject, author, date;
- (NSString *) dateString
{
NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
return [formatter stringFromDate: self.date];
}
- (NSArray*) treeContents
{
+18 -9
View File
@@ -73,30 +73,39 @@ static NSString* gitPath = @"/usr/bin/env";
- (void) initializeCommits
{
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray * newArray = [NSMutableArray array];
NSDate* start = [NSDate date];
NSFileHandle* handle = [self handleForCommand:@"log --pretty=format:%H\01%s\01%an HEAD"];
NSString* currentLine = [handle readLine];
NSFileHandle* handle = [self handleForCommand:@"log --pretty=format:%H\01%an\01%s\01%at HEAD"];
int fd = [handle fileDescriptor];
FILE* f = fdopen(fd, "r");
char buffer[2050];
buffer[2049] = 0;
char* l;
int num = 0;
while (currentLine.length > 0) {
while (l = fgets(buffer, 2048, f)) {
NSString* currentLine = [NSString stringWithCString:(const char *)l encoding:NSUTF8StringEncoding];
if ([currentLine length] == 0)
currentLine = [NSString stringWithCString:(const char *)l encoding:NSASCIIStringEncoding];
NSArray* components = [currentLine componentsSeparatedByString:@"\01"];
PBGitCommit* newCommit = [[PBGitCommit alloc] initWithRepository: self andSha: [components objectAtIndex:0]];
newCommit.subject = [components objectAtIndex:1];
newCommit.author = [components objectAtIndex:2];
newCommit.subject = [components objectAtIndex:2];
newCommit.author = [components objectAtIndex:1];
newCommit.date = [NSDate dateWithTimeIntervalSince1970:[[components objectAtIndex:3] intValue]];
[newArray addObject: newCommit];
num++;
if (num % 1000 == 0)
if (num % 10000 == 0)
[self performSelectorOnMainThread:@selector(setCommits:) withObject:newArray waitUntilDone:NO];
currentLine = [handle readLine];
}
[self performSelectorOnMainThread:@selector(setCommits:) withObject:newArray waitUntilDone:YES];
NSTimeInterval duration = [[NSDate date] timeIntervalSinceDate:start];
NSLog(@"Loaded %i commits in %f seconds", num, duration);
//[pool release];
[NSThread exit];
}