{"thread":{"id":"18723","subject":"[PATCH 4/4] replace_object: use the new generic \"sha1_pos\" function to lookup sha1","startedAt":"2009-04-04T20:59:41Z","lastAt":"2009-04-05T13:19:25Z","messageCount":2,"participants":["Christian Couder","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"110348","messageId":"20090404225941.7fef76a7.chriscool@tuxfamily.org","threadId":"18723","inReplyTo":null,"subject":"[PATCH 4/4] replace_object: use the new generic \"sha1_pos\" function to lookup sha1","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-04-04T20:59:41Z","receivedAt":"2009-04-04T20:59:41Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"instead of the specific one that was simpler but less efficient.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n replace_object.c |   24 +++++++++---------------\n 1 files changed, 9 insertions(+), 15 deletions(-)\n\ndiff --git a/replace_object.c b/replace_object.c\nindex 1227214..eb59604 100644\n--- a/replace_object.c\n+++ b/replace_object.c\n@@ -1,4 +1,5 @@\n #include \"cache.h\"\n+#include \"sha1-lookup.h\"\n #include \"refs.h\"\n \n static struct replace_object {\n@@ -7,23 +8,16 @@ static struct replace_object {\n \n static int replace_object_alloc, replace_object_nr;\n \n+static const unsigned char *replace_sha1_access(size_t index, void *table)\n+{\n+\tstruct replace_object **replace = table;\n+\treturn replace[index]->sha1[0];\n+}\n+\n static int replace_object_pos(const unsigned char *sha1)\n {\n-\tint lo, hi;\n-\tlo = 0;\n-\thi = replace_object_nr;\n-\twhile (lo < hi) {\n-\t\tint mi = (lo + hi) / 2;\n-\t\tstruct replace_object *rep = replace_object[mi];\n-\t\tint cmp = hashcmp(sha1, rep->sha1[0]);\n-\t\tif (!cmp)\n-\t\t\treturn mi;\n-\t\tif (cmp < 0)\n-\t\t\thi = mi;\n-\t\telse\n-\t\t\tlo = mi + 1;\n-\t}\n-\treturn -lo - 1;\n+\treturn sha1_pos(sha1, replace_object, replace_object_nr,\n+\t\t\treplace_sha1_access);\n }\n \n static int register_replace_object(struct replace_object *replace,\n-- \n1.6.2.2.404.ge96f3.dirty\n"},{"id":"110412","messageId":"alpine.DEB.1.00.0904051516170.10279@pacific.mpi-cbg.de","threadId":"18723","inReplyTo":"20090404225941.7fef76a7.chriscool@tuxfamily.org","subject":"Re: [PATCH 4/4] replace_object: use the new generic \"sha1_pos\" function to lookup sha1","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-04-05T13:19:25Z","receivedAt":"2009-04-05T13:19:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 4 Apr 2009, Christian Couder wrote:\n\n> instead of the specific one that was simpler but less efficient.\n> \n> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n> ---\n>  replace_object.c |   24 +++++++++---------------\n>  1 files changed, 9 insertions(+), 15 deletions(-)\n> \n> diff --git a/replace_object.c b/replace_object.c\n> index 1227214..eb59604 100644\n> --- a/replace_object.c\n> +++ b/replace_object.c\n> @@ -1,4 +1,5 @@\n>  #include \"cache.h\"\n> +#include \"sha1-lookup.h\"\n>  #include \"refs.h\"\n>  \n>  static struct replace_object {\n> @@ -7,23 +8,16 @@ static struct replace_object {\n>  \n>  static int replace_object_alloc, replace_object_nr;\n>  \n> +static const unsigned char *replace_sha1_access(size_t index, void *table)\n> +{\n> +\tstruct replace_object **replace = table;\n> +\treturn replace[index]->sha1[0];\n> +}\n\nI have to agree with Junio that this is potentially slowing down things, \nas there is an additional redirection layer here.\n\nIf the tables are not too large, I'd prefer using a\n\n\tstruct sha1_list_entry {\n\t\tunsigned char *sha1;\n\t\tvoid *object;\n\t};\n\nHmm.\n\nCiao,\nDscho\n"}]}