GitRepository: Cache HEAD ref

Since 63523d00e8 (History view:
Make lozenge of currently checked out branch (HEAD) bold, same as gitk.),
-[PBGitRepository headRef] was called every time a cell needed redrawing.

This made GitX slow overall, but especially when resizing the window.

So, it's better to cache the value. We'll still reload it with an
explicit refresh though.
This commit is contained in:
Pieter de Bie
2008-10-14 01:38:06 +02:00
parent b8161654c5
commit 406125eee2
2 changed files with 11 additions and 3 deletions
+2
View File
@@ -19,6 +19,8 @@ extern NSString* PBGitRepositoryErrorDomain;
NSMutableArray* branches;
NSIndexSet* currentBranch;
NSMutableDictionary* refs;
PBGitRevSpecifier *_headRef; // Caching
}
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
+9 -3
View File
@@ -188,6 +188,7 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
// returns YES when a ref was changed
- (BOOL) reloadRefs
{
_headRef = nil;
BOOL ret = NO;
refs = [NSMutableDictionary dictionary];
@@ -233,13 +234,18 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
hasChanged = NO;
}
- (PBGitRevSpecifier*) headRef
- (PBGitRevSpecifier *)headRef
{
if (_headRef)
return _headRef;
NSString* branch = [self parseSymbolicReference: @"HEAD"];
if (branch && [branch hasPrefix:@"refs/heads/"])
return [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:branch]];
_headRef = [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:branch]];
else
_headRef = [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:@"HEAD"]];
return [[PBGitRevSpecifier alloc] initWithRef:[PBGitRef refFromString:@"HEAD"]];
return _headRef;
}
// Returns either this object, or an existing, equal object