From: Yann Dirson <ydirson@altern.org>
To: git@vger.kernel.org
Cc: Yann Dirson <ydirson@altern.org>
Subject: [PATCH 3/6] Convert diffcore-rename's rename_src to the new sorted-array API.
Date: Mon, 29 Nov 2010 23:57:18 +0100 [thread overview]
Message-ID: <1291071441-11808-4-git-send-email-ydirson@altern.org> (raw)
In-Reply-To: <1291071441-11808-1-git-send-email-ydirson@altern.org>
There was no compelling reason to pass separately two members of a
single struct to the insert function. That's a happy coincidence.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
diffcore-rename.c | 57 ++++++++++++++++++----------------------------------
1 files changed, 20 insertions(+), 37 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index a655017..7e35a82 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -37,46 +37,29 @@ declare_sorted_array_insert_checkbool(static, register_rename_dst, struct diff_f
rename_dst, rename_dst_cmp, rename_dst_init);
/* Table of rename/copy src files */
-static struct diff_rename_src {
+
+struct diff_rename_src {
struct diff_filespec *one;
unsigned short score; /* to remember the break score */
-} *rename_src;
-static int rename_src_nr, rename_src_alloc;
+};
-static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
- unsigned short score)
+static int rename_src_cmp(struct diff_filepair *ref_pair, struct diff_rename_src *elem)
{
- int first, last;
-
- first = 0;
- last = rename_src_nr;
- while (last > first) {
- int next = (last + first) >> 1;
- struct diff_rename_src *src = &(rename_src[next]);
- int cmp = strcmp(one->path, src->one->path);
- if (!cmp)
- return src;
- if (cmp < 0) {
- last = next;
- continue;
- }
- first = next+1;
- }
-
- /* insert to make it at "first" */
- if (rename_src_alloc <= rename_src_nr) {
- rename_src_alloc = alloc_nr(rename_src_alloc);
- rename_src = xrealloc(rename_src,
- rename_src_alloc * sizeof(*rename_src));
- }
- rename_src_nr++;
- if (first < rename_src_nr)
- memmove(rename_src + first + 1, rename_src + first,
- (rename_src_nr - first - 1) * sizeof(*rename_src));
- rename_src[first].one = one;
- rename_src[first].score = score;
- return &(rename_src[first]);
+ return strcmp(ref_pair->one->path, elem->one->path);
+}
+static void rename_src_init(struct diff_rename_src *elem, struct diff_filepair *ref_pair)
+{
+ elem->one = ref_pair->one;
+ elem->score = ref_pair->score;
}
+declare_sorted_array(static, struct diff_rename_src, rename_src);
+declare_gen_binsearch(static, struct diff_rename_src, _locate_rename_src,
+ struct diff_filepair *);
+declare_gen_sorted_insert(static, struct diff_rename_src, _register_rename_src,
+ _locate_rename_src, struct diff_filepair *);
+declare_sorted_array_insert_checkbool(static, register_rename_src, struct diff_filepair *,
+ _register_rename_src,
+ rename_src, rename_src_cmp, rename_src_init);
static int basename_same(struct diff_filespec *src, struct diff_filespec *dst)
{
@@ -433,7 +416,7 @@ void diffcore_rename(struct diff_options *options)
*/
if (p->broken_pair && !p->score)
p->one->rename_used++;
- register_rename_src(p->one, p->score);
+ register_rename_src(p);
}
else if (detect_rename == DIFF_DETECT_COPY) {
/*
@@ -441,7 +424,7 @@ void diffcore_rename(struct diff_options *options)
* one, to indicate ourselves as a user.
*/
p->one->rename_used++;
- register_rename_src(p->one, p->score);
+ register_rename_src(p);
}
}
if (rename_dst_nr == 0 || rename_src_nr == 0)
--
1.7.2.3
next prev parent reply other threads:[~2010-11-29 22:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-29 22:57 [PATCH v4] generalizing sorted-array handling Yann Dirson
2010-11-29 22:57 ` [PATCH 1/6] Introduce sorted-array binary-search function Yann Dirson
2010-11-29 22:57 ` [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API Yann Dirson
2010-11-29 22:57 ` Yann Dirson [this message]
2010-11-29 22:57 ` [PATCH 4/6] Convert pack-objects.c " Yann Dirson
2010-11-29 22:57 ` [PATCH 5/6] Use sorted-array API for commit.c's commit_graft Yann Dirson
2010-11-29 22:57 ` [PATCH 6/6] [WIP] subvert sorted-array to replace binary-search in unpack-objects Yann Dirson
-- strict thread matches above, loose matches on Subject: below --
2010-12-05 10:34 [PATCH v5] generalizing sorted-array handling Yann Dirson
2010-12-05 10:34 ` [PATCH 3/6] Convert diffcore-rename's rename_src to the new sorted-array API Yann Dirson
2010-12-08 22:51 [PATCH v6] generalizing sorted-array handling Yann Dirson
2010-12-08 22:51 ` [PATCH 3/6] Convert diffcore-rename's rename_src 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291071441-11808-4-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).