summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c70
1 files changed, 20 insertions, 50 deletions
diff --git a/diff.c b/diff.c
index 9aff167be2..78a486021a 100644
--- a/diff.c
+++ b/diff.c
@@ -879,37 +879,21 @@ static int compute_ws_delta(const struct emitted_diff_symbol *a,
return 1;
}
-static int cmp_in_block_with_wsd(const struct diff_options *o,
- const struct moved_entry *cur,
- const struct moved_entry *match,
- struct moved_block *pmb,
- int n)
-{
- struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
- int al = cur->es->len, bl = match->es->len, cl = l->len;
+static int cmp_in_block_with_wsd(const struct moved_entry *cur,
+ const struct emitted_diff_symbol *l,
+ struct moved_block *pmb)
+{
+ int al = cur->es->len, bl = l->len;
const char *a = cur->es->line,
- *b = match->es->line,
- *c = l->line;
+ *b = l->line;
int a_off = cur->es->indent_off,
a_width = cur->es->indent_width,
- c_off = l->indent_off,
- c_width = l->indent_width;
+ b_off = l->indent_off,
+ b_width = l->indent_width;
int delta;
- /*
- * We need to check if 'cur' is equal to 'match'. As those
- * are from the same (+/-) side, we do not need to adjust for
- * indent changes. However these were found using fuzzy
- * matching so we do have to check if they are equal. Here we
- * just check the lengths. We delay calling memcmp() to check
- * the contents until later as if the length comparison for a
- * and c fails we can avoid the call all together.
- */
- if (al != bl)
- return 1;
-
/* If 'l' and 'cur' are both blank then they match. */
- if (a_width == INDENT_BLANKLINE && c_width == INDENT_BLANKLINE)
+ if (a_width == INDENT_BLANKLINE && b_width == INDENT_BLANKLINE)
return 0;
/*
@@ -918,7 +902,7 @@ static int cmp_in_block_with_wsd(const struct diff_options *o,
* match those of the current block and that the text of 'l' and 'cur'
* after the indentation match.
*/
- delta = c_width - a_width;
+ delta = b_width - a_width;
/*
* If the previous lines of this block were all blank then set its
@@ -927,9 +911,8 @@ static int cmp_in_block_with_wsd(const struct diff_options *o,
if (pmb->wsd == INDENT_BLANKLINE)
pmb->wsd = delta;
- return !(delta == pmb->wsd && al - a_off == cl - c_off &&
- !memcmp(a, b, al) && !
- memcmp(a + a_off, c + c_off, al - a_off));
+ return !(delta == pmb->wsd && al - a_off == bl - b_off &&
+ !memcmp(a + a_off, b + b_off, al - a_off));
}
static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
@@ -1030,36 +1013,23 @@ static void pmb_advance_or_null(struct diff_options *o,
}
static void pmb_advance_or_null_multi_match(struct diff_options *o,
- struct moved_entry *match,
- struct hashmap *hm,
+ struct emitted_diff_symbol *l,
struct moved_block *pmb,
- int pmb_nr, int n)
+ int pmb_nr)
{
int i;
- char *got_match = xcalloc(1, pmb_nr);
-
- hashmap_for_each_entry_from(hm, match, ent) {
- for (i = 0; i < pmb_nr; i++) {
- struct moved_entry *prev = pmb[i].match;
- struct moved_entry *cur = (prev && prev->next_line) ?
- prev->next_line : NULL;
- if (!cur)
- continue;
- if (!cmp_in_block_with_wsd(o, cur, match, &pmb[i], n))
- got_match[i] |= 1;
- }
- }
for (i = 0; i < pmb_nr; i++) {
- if (got_match[i]) {
+ struct moved_entry *prev = pmb[i].match;
+ struct moved_entry *cur = (prev && prev->next_line) ?
+ prev->next_line : NULL;
+ if (cur && !cmp_in_block_with_wsd(cur, l, &pmb[i])) {
/* Advance to the next line */
- pmb[i].match = pmb[i].match->next_line;
+ pmb[i].match = cur;
} else {
moved_block_clear(&pmb[i]);
}
}
-
- free(got_match);
}
static int shrink_potential_moved_blocks(struct moved_block *pmb,
@@ -1223,7 +1193,7 @@ static void mark_color_as_moved(struct diff_options *o,
if (o->color_moved_ws_handling &
COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE)
- pmb_advance_or_null_multi_match(o, match, hm, pmb, pmb_nr, n);
+ pmb_advance_or_null_multi_match(o, l, pmb, pmb_nr);
else
pmb_advance_or_null(o, match, hm, pmb, pmb_nr);