From 3c39e9bdebd68d8d45b3900bc21171642f4c6125 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 1 Feb 2006 23:29:03 -0800 Subject: [PATCH] combine-diff: reuse diff from the same blob. When dealing with an insanely large Octopus, it is possible to optimize by noticing that more than one parents have the same blob and avoid running diff between a parent and the merge result by reusing an earlier result. Signed-off-by: Junio C Hamano --- combine-diff.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/combine-diff.c b/combine-diff.c index 243f96775..0cc18feb6 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -523,6 +523,30 @@ static void dump_sline(struct sline *sline, int cnt, int num_parent) } } +static void reuse_combine_diff(struct sline *sline, unsigned long cnt, + int i, int j) +{ + /* We have already examined parent j and we know parent i + * and parent j are the same, so reuse the combined result + * of parent j for parent i. + */ + unsigned long lno, imask, jmask; + imask = (1UL<lost_head; + while (ll) { + if (ll->parent_map & jmask) + ll->parent_map |= imask; + ll = ll->next; + } + if (!(sline->flag & jmask)) + sline->flag &= ~imask; + sline++; + } +} + int show_combined_diff(struct combine_diff_path *elem, int num_parent, int dense, const char *header, int show_empty) { @@ -596,8 +620,19 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent, sline[cnt-1].flag = (1UL<parent_sha1[i], ourtmp, sline, cnt, i); + for (i = 0; i < num_parent; i++) { + int j; + for (j = 0; j < i; j++) { + if (!memcmp(elem->parent_sha1[i], + elem->parent_sha1[j], 20)) { + reuse_combine_diff(sline, cnt, i, j); + break; + } + } + if (i <= j) + combine_diff(elem->parent_sha1[i], ourtmp, sline, + cnt, i); + } show_hunks = make_hunks(sline, cnt, num_parent, dense); -- 2.11.4.GIT