summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c3e3cd4)
raw | patch | inline | side by side (parent: c3e3cd4)
author | Shawn O. Pearce <spearce@spearce.org> | |
Sat, 13 Jan 2007 22:29:00 +0000 (17:29 -0500) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 15 Jan 2007 05:17:27 +0000 (21:17 -0800) |
If a project has a really huge number of tags (such as several
thousand tags) then we are likely to have nearly a hundred tags in
some buckets. Scanning those buckets as linked lists could take
a large amount of time if done repeatedly during history traversal.
Since we are searching for a unique commit SHA1 we can sort all
tags by commit SHA1 and perform a binary search within the bucket.
Once we identify a particular tag as matching this commit we walk
backwards within the bucket matches to make sure we pick up the
highest priority tag for that commit, as the binary search may
have landed us in the middle of a set of tags which point at the
same commit.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
thousand tags) then we are likely to have nearly a hundred tags in
some buckets. Scanning those buckets as linked lists could take
a large amount of time if done repeatedly during history traversal.
Since we are searching for a unique commit SHA1 we can sort all
tags by commit SHA1 and perform a binary search within the bucket.
Once we identify a particular tag as matching this commit we walk
backwards within the bucket matches to make sure we pick up the
highest priority tag for that commit, as the binary search may
have landed us in the middle of a set of tags which point at the
same commit.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-describe.c | patch | blob | history |
diff --git a/builtin-describe.c b/builtin-describe.c
index 582ef023f7c8d00576c403ec80b7e541d3edf494..5d6865b165043096f6151138bc1c6e5ffc5be3a8 100644 (file)
--- a/builtin-describe.c
+++ b/builtin-describe.c
static struct commit_name *match(struct commit *cmit)
{
- unsigned char m = cmit->object.sha1[0];
- unsigned int i = names[m];
- struct commit_name **p = name_array[m];
-
- while (i-- > 0) {
- struct commit_name *n = *p++;
- if (n->commit == cmit)
- return n;
+ unsigned char level0 = cmit->object.sha1[0];
+ struct commit_name **p = name_array[level0];
+ unsigned int hi = names[level0];
+ unsigned int lo = 0;
+
+ while (lo < hi) {
+ unsigned int mi = (lo + hi) / 2;
+ int cmp = hashcmp(p[mi]->commit->object.sha1,
+ cmit->object.sha1);
+ if (!cmp) {
+ while (mi && p[mi - 1]->commit == cmit)
+ mi--;
+ return p[mi];
+ }
+ if (cmp > 0)
+ hi = mi;
+ else
+ lo = mi+1;
}
return NULL;
}
struct commit_name *b = *(struct commit_name **)_b;
unsigned long a_date = a->commit->date;
unsigned long b_date = b->commit->date;
+ int cmp = hashcmp(a->commit->object.sha1, b->commit->object.sha1);
+ if (cmp)
+ return cmp;
if (a->prio != b->prio)
return b->prio - a->prio;
return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;