git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/4] replace_object: use the new generic "sha1_pos" function to lookup sha1
@ 2009-04-04 20:59 Christian Couder
  2009-04-05 13:19 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Couder @ 2009-04-04 20:59 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

instead of the specific one that was simpler but less efficient.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 replace_object.c |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/replace_object.c b/replace_object.c
index 1227214..eb59604 100644
--- a/replace_object.c
+++ b/replace_object.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "sha1-lookup.h"
 #include "refs.h"
 
 static struct replace_object {
@@ -7,23 +8,16 @@ static struct replace_object {
 
 static int replace_object_alloc, replace_object_nr;
 
+static const unsigned char *replace_sha1_access(size_t index, void *table)
+{
+	struct replace_object **replace = table;
+	return replace[index]->sha1[0];
+}
+
 static int replace_object_pos(const unsigned char *sha1)
 {
-	int lo, hi;
-	lo = 0;
-	hi = replace_object_nr;
-	while (lo < hi) {
-		int mi = (lo + hi) / 2;
-		struct replace_object *rep = replace_object[mi];
-		int cmp = hashcmp(sha1, rep->sha1[0]);
-		if (!cmp)
-			return mi;
-		if (cmp < 0)
-			hi = mi;
-		else
-			lo = mi + 1;
-	}
-	return -lo - 1;
+	return sha1_pos(sha1, replace_object, replace_object_nr,
+			replace_sha1_access);
 }
 
 static int register_replace_object(struct replace_object *replace,
-- 
1.6.2.2.404.ge96f3.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 4/4] replace_object: use the new generic "sha1_pos" function to lookup sha1
  2009-04-04 20:59 [PATCH 4/4] replace_object: use the new generic "sha1_pos" function to lookup sha1 Christian Couder
@ 2009-04-05 13:19 ` Johannes Schindelin
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin @ 2009-04-05 13:19 UTC (permalink / raw)
  To: Christian Couder; +Cc: Junio C Hamano, git

Hi,

On Sat, 4 Apr 2009, Christian Couder wrote:

> instead of the specific one that was simpler but less efficient.
> 
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  replace_object.c |   24 +++++++++---------------
>  1 files changed, 9 insertions(+), 15 deletions(-)
> 
> diff --git a/replace_object.c b/replace_object.c
> index 1227214..eb59604 100644
> --- a/replace_object.c
> +++ b/replace_object.c
> @@ -1,4 +1,5 @@
>  #include "cache.h"
> +#include "sha1-lookup.h"
>  #include "refs.h"
>  
>  static struct replace_object {
> @@ -7,23 +8,16 @@ static struct replace_object {
>  
>  static int replace_object_alloc, replace_object_nr;
>  
> +static const unsigned char *replace_sha1_access(size_t index, void *table)
> +{
> +	struct replace_object **replace = table;
> +	return replace[index]->sha1[0];
> +}

I have to agree with Junio that this is potentially slowing down things, 
as there is an additional redirection layer here.

If the tables are not too large, I'd prefer using a

	struct sha1_list_entry {
		unsigned char *sha1;
		void *object;
	};

Hmm.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-04-05 13:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-04 20:59 [PATCH 4/4] replace_object: use the new generic "sha1_pos" function to lookup sha1 Christian Couder
2009-04-05 13:19 ` Johannes Schindelin

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 NNTP newsgroup(s).