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 <junkio@cox.net>
Junio C Hamano committed
Feb 1, 2006 at 23:29 UTC
3c39e9bdebd68d8d45b3900bc21171642f4c6125
1 file changed
+37
-2
combine-diff.c
+37
-2
@@ -523,6 +523,30 @@ static void dump_sline(struct sline *sline, int cnt, int num_parent)
523
}
524
}
525
526
+static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
527
+ int i, int j)
528
+{
529
+ /* We have already examined parent j and we know parent i
530
+ * and parent j are the same, so reuse the combined result
531
+ * of parent j for parent i.
532
+ */
533
+ unsigned long lno, imask, jmask;
534
+ imask = (1UL<<i);
535
+ jmask = (1UL<<j);
536
+
537
+ for (lno = 0; lno < cnt; lno++) {
538
+ struct lline *ll = sline->lost_head;
539
+ while (ll) {
540
+ if (ll->parent_map & jmask)
541
+ ll->parent_map |= imask;
542
+ ll = ll->next;
543
+ }
544
+ if (!(sline->flag & jmask))
545
+ sline->flag &= ~imask;
546
+ sline++;
547
+ }
548
+}
549
+
550
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
551
int dense, const char *header, int show_empty)
552
{
@@ -596,8 +620,19 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
620
sline[cnt-1].flag = (1UL<<num_parent) - 1;
621
}
622
599
- for (i = 0; i < num_parent; i++)
600
- combine_diff(elem->parent_sha1[i], ourtmp, sline, cnt, i);
623
+ for (i = 0; i < num_parent; i++) {
624
+ int j;
625
+ for (j = 0; j < i; j++) {
626
+ if (!memcmp(elem->parent_sha1[i],
627
+ elem->parent_sha1[j], 20)) {
628
+ reuse_combine_diff(sline, cnt, i, j);
629
+ break;
630
+ }
631
+ }
632
+ if (i <= j)
633
+ combine_diff(elem->parent_sha1[i], ourtmp, sline,
634
+ cnt, i);
635
+ }
636
637
show_hunks = make_hunks(sline, cnt, num_parent, dense);
638