From: Yann Dirson <ydirson@altern.org>
To: git@vger.kernel.org
Cc: Yann Dirson <ydirson@altern.org>
Subject: [PATCH 6/6] [WIP] subvert sorted-array to replace binary-search in unpack-objects.
Date: Sun, 5 Dec 2010 11:34:07 +0100 [thread overview]
Message-ID: <1291545247-4151-7-git-send-email-ydirson@altern.org> (raw)
In-Reply-To: <1291545247-4151-1-git-send-email-ydirson@altern.org>
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
builtin/unpack-objects.c | 41 ++++++++++++++++++++++++++---------------
1 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f63973c..b0c15e6 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -11,6 +11,7 @@
#include "progress.h"
#include "decorate.h"
#include "fsck.h"
+#include "sorted-array.h"
static int dry_run, quiet, recover, has_errors, strict;
static const char unpack_usage[] = "git unpack-objects [-n] [-q] [-r] [--strict] < pack-file";
@@ -157,7 +158,25 @@ struct obj_info {
#define FLAG_OPEN (1u<<20)
#define FLAG_WRITTEN (1u<<21)
-static struct obj_info *obj_list;
+/*
+ * FIXME: obj_info is a sorted array, but we read it as a whole, we
+ * don't need insertion features. This allows us to abuse unused
+ * obj_info_nr later as a means of specifying an upper bound for
+ * binary search. obj_info_alloc shall be eliminated by the compiler
+ * as unused.
+ */
+static int obj_info_cmp(off_t ref, struct obj_info *elem)
+{
+ if (ref == elem->offset)
+ return 0;
+ if (ref < elem->offset)
+ return -1;
+ return 1;
+}
+declare_sorted_array(static, struct obj_info, obj_list);
+declare_gen_binsearch(static, struct obj_info, _obj_list_check, off_t);
+declare_sorted_array_search_check(static, obj_list_check, off_t, _obj_list_check,
+ obj_list, obj_info_cmp);
static unsigned nr_objects;
/*
@@ -356,7 +375,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
unsigned base_found = 0;
unsigned char *pack, c;
off_t base_offset;
- unsigned lo, mid, hi;
+ int pos;
pack = fill(1);
c = *pack;
@@ -380,19 +399,11 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
free(delta_data);
return;
}
- lo = 0;
- hi = nr;
- while (lo < hi) {
- mid = (lo + hi)/2;
- if (base_offset < obj_list[mid].offset) {
- hi = mid;
- } else if (base_offset > obj_list[mid].offset) {
- lo = mid + 1;
- } else {
- hashcpy(base_sha1, obj_list[mid].sha1);
- base_found = !is_null_sha1(base_sha1);
- break;
- }
+ obj_list_nr = nr; /* kludge to bound the search */
+ pos = obj_list_check(base_offset);
+ if (pos >= 0) {
+ hashcpy(base_sha1, obj_list[pos].sha1);
+ base_found = !is_null_sha1(base_sha1);
}
if (!base_found) {
/*
--
1.7.2.3
next prev parent reply other threads:[~2010-12-05 10:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-05 10:34 [PATCH v5] generalizing sorted-array handling Yann Dirson
2010-12-05 10:34 ` [PATCH 1/6] Introduce sorted-array binary-search function Yann Dirson
2010-12-05 10:34 ` [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API Yann Dirson
2010-12-05 10:34 ` [PATCH 3/6] Convert diffcore-rename's rename_src " Yann Dirson
2010-12-05 10:34 ` [PATCH 4/6] Convert pack-objects.c " Yann Dirson
2010-12-05 10:34 ` [PATCH 5/6] Use sorted-array API for commit.c's commit_graft Yann Dirson
2010-12-05 10:34 ` Yann Dirson [this message]
2010-12-05 10:44 ` [PATCH v5] generalizing sorted-array handling Jonathan Nieder
2010-12-05 12:02 ` Yann Dirson
-- strict thread matches above, loose matches on Subject: below --
2010-11-29 22:57 [PATCH v4] " Yann Dirson
2010-11-29 22:57 ` [PATCH 6/6] [WIP] subvert sorted-array to replace binary-search in unpack-objects Yann Dirson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291545247-4151-7-git-send-email-ydirson@altern.org \
--to=ydirson@altern.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).