mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
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:
@@ -19,6 +19,8 @@ extern NSString* PBGitRepositoryErrorDomain;
|
||||
NSMutableArray* branches;
|
||||
NSIndexSet* currentBranch;
|
||||
NSMutableDictionary* refs;
|
||||
|
||||
PBGitRevSpecifier *_headRef; // Caching
|
||||
}
|
||||
|
||||
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
|
||||
|
||||
+9
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user