git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] commit: use the generic "sha1_pos" function to lookup sha1
@ 2010-03-20  9:51 Bo Yang
  0 siblings, 0 replies; only message in thread
From: Bo Yang @ 2010-03-20  9:51 UTC (permalink / raw
  To: git; +Cc: Bo Yang

Replace different binary search function with a generic one.


Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
 commit.c |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/commit.c b/commit.c
index 731191e..dba67d5 100644
--- a/commit.c
+++ b/commit.c
@@ -6,6 +6,7 @@
 #include "diff.h"
 #include "revision.h"
 #include "notes.h"
+#include "sha1-lookup.h"
 
 int save_commit_buffer = 1;
 
@@ -79,23 +80,16 @@ static unsigned long parse_commit_date(const char *buf, const char *tail)
 static struct commit_graft **commit_graft;
 static int commit_graft_alloc, commit_graft_nr;
 
+static const unsigned char *commit_sha1_access(size_t index, void *table)
+{
+	struct commit_graft **graft = table;
+	return graft[index]->sha1;
+}
+
 static int commit_graft_pos(const unsigned char *sha1)
 {
-	int lo, hi;
-	lo = 0;
-	hi = commit_graft_nr;
-	while (lo < hi) {
-		int mi = (lo + hi) / 2;
-		struct commit_graft *graft = commit_graft[mi];
-		int cmp = hashcmp(sha1, graft->sha1);
-		if (!cmp)
-			return mi;
-		if (cmp < 0)
-			hi = mi;
-		else
-			lo = mi + 1;
-	}
-	return -lo - 1;
+	return sha1_pos(sha1, commit_graft, commit_graft_nr,
+		commit_sha1_access);
 }
 
 int register_commit_graft(struct commit_graft *graft, int ignore_dups)
-- 
1.7.0.2.273.gc2413.dirty

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-03-20  9:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-20  9:51 [PATCH] commit: use the generic "sha1_pos" function to lookup sha1 Bo Yang

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).