Skip to content

Commit

Permalink
PBGitCommit: Don't store refs
Browse files Browse the repository at this point in the history
We already keep this dictionary in our repository. Rather than adding a
pointer to it on every commit in our rev walk, just look it up lazily in the
dictionary when we need to. That cuts down some time in the initial revwalk
and also removes some stupid code :)
  • Loading branch information
pieter committed Jan 25, 2009
1 parent 4f1fe8a commit ddc9ae7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion PBGitCommit.h
Expand Up @@ -21,7 +21,7 @@
NSString* details;
NSString *_patch;
NSArray* parents;
NSMutableArray* refs;

int timestamp;
char sign;
id lineInfo;
Expand Down
18 changes: 14 additions & 4 deletions PBGitCommit.m
Expand Up @@ -11,7 +11,7 @@

@implementation PBGitCommit

@synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo, refs;
@synthesize repository, subject, timestamp, author, parentShas, nParents, sign, lineInfo;

- (NSArray *) parents
{
Expand Down Expand Up @@ -107,9 +107,19 @@ - (void)removeRef:(id)ref
if (!self.refs)
return;

[refs removeObject:ref];
if ([refs count] == 0)
refs = NULL;
[self.refs removeObject:ref];
if ([self.refs count] == 0)
self.refs = NULL;
}

- (NSMutableArray *)refs
{
return [[repository refs] objectForKey:[self realSha]];
}

- (void) setRefs:(NSMutableArray *)refs
{
[[repository refs] setObject:[self realSha] forKey:[self realSha]];
}

- (void)finalize
Expand Down
2 changes: 0 additions & 2 deletions PBGitGrapher.h
Expand Up @@ -15,8 +15,6 @@
PBGraphCellInfo *previous;
void *pl;
int curLane;

NSDictionary *refs;
}

- (id) initWithRepository:(PBGitRepository *)repo;
Expand Down
1 change: 0 additions & 1 deletion PBGitGrapher.mm
Expand Up @@ -21,7 +21,6 @@ @implementation PBGitGrapher

- (id) initWithRepository: (PBGitRepository*) repo
{
refs = repo.refs;
pl = new std::list<PBGitLane *>;

PBGitLane::resetColors();
Expand Down
2 changes: 1 addition & 1 deletion PBGitRepository.h
Expand Up @@ -62,5 +62,5 @@ extern NSString* PBGitRepositoryErrorDomain;
@property (retain) PBGitRevList* revisionList;
@property (assign) NSMutableArray* branches;
@property (assign) PBGitRevSpecifier *currentBranch;
@property (assign) NSMutableDictionary* refs;
@property (retain) NSMutableDictionary* refs;
@end
2 changes: 0 additions & 2 deletions PBGitRepository.m
Expand Up @@ -228,8 +228,6 @@ - (BOOL) reloadRefs
[self addRef:newRef fromParameters:components];
}

self.refs = refs;

// Add an "All branches" option in the branches list
[self addBranch:[PBGitRevSpecifier allBranchesRevSpec]];
[self addBranch:[PBGitRevSpecifier localBranchesRevSpec]];
Expand Down
7 changes: 1 addition & 6 deletions PBGitRevList.mm
Expand Up @@ -71,7 +71,6 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev
NSDate *start = [NSDate date];
NSMutableArray* revisions = [NSMutableArray array];
PBGitGrapher* g = [[PBGitGrapher alloc] initWithRepository: repository];
NSDictionary* refs = [repository refs];

NSMutableArray* arguments;
BOOL showSign = [rev hasLeftRight];
Expand Down Expand Up @@ -170,11 +169,7 @@ - (void) walkRevisionListWithSpecifier: (PBGitRevSpecifier*) rev

[revisions addObject: newCommit];
[g decorateCommit: newCommit];

// 0.1 second on linux-2.6
if (refs && [refs objectForKey:[newCommit realSha]])
newCommit.refs = [refs objectForKey:[newCommit realSha]];


if (++num % 1000 == 0)
[self performSelectorOnMainThread:@selector(setCommits:) withObject:revisions waitUntilDone:NO];
}
Expand Down
2 changes: 1 addition & 1 deletion html/views/history/history.js
Expand Up @@ -2,7 +2,7 @@ var commit;
var Commit = function(obj) {
this.object = obj;

this.refs = obj.refs;
this.refs = obj.refs();
this.author_name = obj.author;
this.sha = obj.realSha();
this.parents = obj.parents;
Expand Down

0 comments on commit ddc9ae7

Please sign in to comment.