Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GitRepository: Cache HEAD ref

Since 63523d0 (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.
  • Loading branch information...
commit 406125eee233a49e59c066e04371698df151ea10 1 parent b816165
@pieter authored
Showing with 11 additions and 3 deletions.
  1. +2 −0  PBGitRepository.h
  2. +9 −3 PBGitRepository.m
View
2  PBGitRepository.h
@@ -19,6 +19,8 @@ extern NSString* PBGitRepositoryErrorDomain;
NSMutableArray* branches;
NSIndexSet* currentBranch;
NSMutableDictionary* refs;
+
+ PBGitRevSpecifier *_headRef; // Caching
}
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
View
12 PBGitRepository.m
@@ -188,6 +188,7 @@ - (void) addRef: (PBGitRef *) ref fromParameters: (NSArray *) components
// returns YES when a ref was changed
- (BOOL) reloadRefs
{
+ _headRef = nil;
BOOL ret = NO;
refs = [NSMutableDictionary dictionary];
@@ -233,13 +234,18 @@ - (void) lazyReload
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
Please sign in to comment.
Something went wrong with that request. Please try again.