From: Yann Dirson <ydirson@altern.org>
To: git@vger.kernel.org
Cc: Yann Dirson <ydirson@altern.org>
Subject: [PATCH 4/6] Convert pack-objects.c to the new sorted-array API.
Date: Wed, 8 Dec 2010 23:51:33 +0100 [thread overview]
Message-ID: <1291848695-24601-5-git-send-email-ydirson@altern.org> (raw)
In-Reply-To: <1291848695-24601-1-git-send-email-ydirson@altern.org>
In this file the "list size" variable was named in a non-standard way.
The new API forces to use a more common convention.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
builtin/pack-objects.c | 50 +++++++++++++----------------------------------
1 files changed, 14 insertions(+), 36 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f027b3a..c26175c 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -16,6 +16,7 @@
#include "list-objects.h"
#include "progress.h"
#include "refs.h"
+#include "sorted-array.h"
#ifndef NO_PTHREADS
#include <pthread.h>
@@ -871,45 +872,22 @@ static void add_pbase_object(struct tree_desc *tree,
}
}
-static unsigned *done_pbase_paths;
-static int done_pbase_paths_num;
-static int done_pbase_paths_alloc;
-static int done_pbase_path_pos(unsigned hash)
+static int unsigned_cmp(unsigned ref, unsigned *elem)
{
- int lo = 0;
- int hi = done_pbase_paths_num;
- while (lo < hi) {
- int mi = (hi + lo) / 2;
- if (done_pbase_paths[mi] == hash)
- return mi;
- if (done_pbase_paths[mi] < hash)
- hi = mi;
- else
- lo = mi + 1;
- }
- return -lo-1;
+ if (ref == *elem)
+ return 0;
+ if (ref < *elem)
+ return -1;
+ return 1;
}
-
-static int check_pbase_path(unsigned hash)
+static void unsigned_init(unsigned *elem, unsigned ref)
{
- int pos = (!done_pbase_paths) ? -1 : done_pbase_path_pos(hash);
- if (0 <= pos)
- return 1;
- pos = -pos - 1;
- if (done_pbase_paths_alloc <= done_pbase_paths_num) {
- done_pbase_paths_alloc = alloc_nr(done_pbase_paths_alloc);
- done_pbase_paths = xrealloc(done_pbase_paths,
- done_pbase_paths_alloc *
- sizeof(unsigned));
- }
- done_pbase_paths_num++;
- if (pos < done_pbase_paths_num)
- memmove(done_pbase_paths + pos + 1,
- done_pbase_paths + pos,
- (done_pbase_paths_num - pos - 1) * sizeof(unsigned));
- done_pbase_paths[pos] = hash;
- return 0;
+ *elem = ref;
}
+declare_sorted_array(static, unsigned, done_pbase_paths);
+declare_sorted_array_insertonly_checkbool(static, unsigned, check_pbase_path,
+ unsigned,
+ done_pbase_paths, unsigned_cmp, unsigned_init);
static void add_preferred_base_object(const char *name)
{
@@ -987,7 +965,7 @@ static void cleanup_preferred_base(void)
free(done_pbase_paths);
done_pbase_paths = NULL;
- done_pbase_paths_num = done_pbase_paths_alloc = 0;
+ done_pbase_paths_nr = done_pbase_paths_alloc = 0;
}
static void check_object(struct object_entry *entry)
--
1.7.2.3
next prev parent reply other threads:[~2010-12-08 22:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-08 22:51 [PATCH v6] generalizing sorted-array handling Yann Dirson
2010-12-08 22:51 ` [PATCH 1/6] Introduce sorted-array binary-search function Yann Dirson
2010-12-10 22:29 ` Junio C Hamano
2010-12-30 0:40 ` Yann Dirson
2010-12-30 1:06 ` Erik Faye-Lund
2010-12-30 10:49 ` Yann Dirson
2010-12-08 22:51 ` [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API Yann Dirson
2010-12-10 22:32 ` Junio C Hamano
2010-12-08 22:51 ` [PATCH 3/6] Convert diffcore-rename's rename_src " Yann Dirson
2010-12-08 22:51 ` Yann Dirson [this message]
2010-12-08 22:51 ` [PATCH 5/6] Use sorted-array API for commit.c's commit_graft Yann Dirson
2010-12-08 22:51 ` [PATCH 6/6] [RFC] subvert sorted-array to replace binary-search in unpack-objects Yann Dirson
2010-12-10 23:00 ` Junio C Hamano
2010-12-10 23:22 ` [PATCH v6] generalizing sorted-array handling Junio C Hamano
2010-12-30 0:01 ` Yann Dirson
-- strict thread matches above, loose matches on Subject: below --
2010-12-05 10:34 [PATCH v5] " Yann Dirson
2010-12-05 10:34 ` [PATCH 4/6] Convert pack-objects.c to the new sorted-array API Yann Dirson
2010-11-29 22:57 [PATCH v4] generalizing sorted-array handling Yann Dirson
2010-11-29 22:57 ` [PATCH 4/6] Convert pack-objects.c to the new sorted-array API 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291848695-24601-5-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.
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).