diff src/xdiff/xpatience.c @ 25709:d5142d87f898 v8.2.3390

patch 8.2.3390: included xdiff code is outdated Commit: https://github.com/vim/vim/commit/ba02e4720f863fdb456e7023520f0a354eec0dcf Author: Christian Brabandt <cb@256bit.org> Date: Tue Aug 31 20:46:39 2021 +0200 patch 8.2.3390: included xdiff code is outdated Problem: Included xdiff code is outdated. Solution: Sync with xdiff in git 2.33. (Christian Brabandt, closes https://github.com/vim/vim/issues/8431)
author Bram Moolenaar <Bram@vim.org>
date Tue, 31 Aug 2021 21:00:05 +0200
parents 3be01cf0a632
children f84e5db372ea
line wrap: on
line diff
--- a/src/xdiff/xpatience.c
+++ b/src/xdiff/xpatience.c
@@ -20,8 +20,6 @@
  *
  */
 #include "xinclude.h"
-#include "xtypes.h"
-#include "xdiff.h"
 
 /*
  * The basic idea of patience diff is to find lines that are unique in
@@ -69,7 +67,7 @@ struct hashmap {
 		 */
 		unsigned anchor : 1;
 	} *entries, *first, *last;
-	// were common records found?
+	/* were common records found? */
 	unsigned long has_matches;
 	mmfile_t *file1, *file2;
 	xdfenv_t *env;
@@ -78,21 +76,21 @@ struct hashmap {
 
 static int is_anchor(xpparam_t const *xpp, const char *line)
 {
-	size_t i;
-	for (i = 0; i < xpp->anchors_nr; i++) {
+	int i;
+	for (i = 0; i < (int)xpp->anchors_nr; i++) {
 		if (!strncmp(line, xpp->anchors[i], strlen(xpp->anchors[i])))
 			return 1;
 	}
 	return 0;
 }
 
-// The argument "pass" is 1 for the first file, 2 for the second.
+/* The argument "pass" is 1 for the first file, 2 for the second. */
 static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map,
 			  int pass)
 {
 	xrecord_t **records = pass == 1 ?
 		map->env->xdf1.recs : map->env->xdf2.recs;
-	xrecord_t *record = records[line - 1], *other;
+	xrecord_t *record = records[line - 1];
 	/*
 	 * After xdl_prepare_env() (or more precisely, due to
 	 * xdl_classify_record()), the "ha" member of the records (AKA lines)
@@ -106,11 +104,7 @@ static void insert_record(xpparam_t cons
 	int index = (int)((record->ha << 1) % map->alloc);
 
 	while (map->entries[index].line1) {
-		other = map->env->xdf1.recs[map->entries[index].line1 - 1];
-		if (map->entries[index].hash != record->ha ||
-				!xdl_recmatch(record->ptr, record->size,
-					other->ptr, other->size,
-					map->xpp->flags)) {
+		if (map->entries[index].hash != record->ha) {
 			if (++index >= map->alloc)
 				index = 0;
 			continue;
@@ -155,7 +149,7 @@ static int fill_hashmap(mmfile_t *file1,
 	result->xpp = xpp;
 	result->env = env;
 
-	// We know exactly how large we want the hash map
+	/* We know exactly how large we want the hash map */
 	result->alloc = count1 * 2;
 	result->entries = (struct entry *)
 		xdl_malloc(result->alloc * sizeof(struct entry));
@@ -163,11 +157,11 @@ static int fill_hashmap(mmfile_t *file1,
 		return -1;
 	memset(result->entries, 0, result->alloc * sizeof(struct entry));
 
-	// First, fill with entries from the first file
+	/* First, fill with entries from the first file */
 	while (count1--)
 		insert_record(xpp, line1++, result, 1);
 
-	// Then search for matches in the second file
+	/* Then search for matches in the second file */
 	while (count2--)
 		insert_record(xpp, line2++, result, 2);
 
@@ -185,13 +179,13 @@ static int binary_search(struct entry **
 
 	while (left + 1 < right) {
 		int middle = left + (right - left) / 2;
-		// by construction, no two entries can be equal
+		/* by construction, no two entries can be equal */
 		if (sequence[middle]->line2 > entry->line2)
 			right = middle;
 		else
 			left = middle;
 	}
-	// return the index in "sequence", _not_ the sequence length
+	/* return the index in "sequence", _not_ the sequence length */
 	return left;
 }
 
@@ -206,9 +200,10 @@ static int binary_search(struct entry **
  */
 static struct entry *find_longest_common_sequence(struct hashmap *map)
 {
-	struct entry **sequence = (struct entry **)xdl_malloc(map->nr * sizeof(struct entry *));
+	struct entry **sequence = xdl_malloc(map->nr * sizeof(struct entry *));
 	int longest = 0, i;
 	struct entry *entry;
+
 	/*
 	 * If not -1, this entry in sequence must never be overridden.
 	 * Therefore, overriding entries before this has no effect, so
@@ -237,13 +232,13 @@ static struct entry *find_longest_common
 		}
 	}
 
-	// No common unique lines were found
+	/* No common unique lines were found */
 	if (!longest) {
 		xdl_free(sequence);
 		return NULL;
 	}
 
-	// Iterate starting at the last element, adjusting the "next" members
+	/* Iterate starting at the last element, adjusting the "next" members */
 	entry = sequence[longest - 1];
 	entry->next = NULL;
 	while (entry->previous) {
@@ -258,8 +253,7 @@ static int match(struct hashmap *map, in
 {
 	xrecord_t *record1 = map->env->xdf1.recs[line1 - 1];
 	xrecord_t *record2 = map->env->xdf2.recs[line2 - 1];
-	return xdl_recmatch(record1->ptr, record1->size,
-		record2->ptr, record2->size, map->xpp->flags);
+	return record1->ha == record2->ha;
 }
 
 static int patience_diff(mmfile_t *file1, mmfile_t *file2,
@@ -273,7 +267,7 @@ static int walk_common_sequence(struct h
 	int next1, next2;
 
 	for (;;) {
-		// Try to grow the line ranges of common lines
+		/* Try to grow the line ranges of common lines */
 		if (first) {
 			next1 = first->line1;
 			next2 = first->line2;
@@ -292,11 +286,8 @@ static int walk_common_sequence(struct h
 			line2++;
 		}
 
-		// Recurse
+		/* Recurse */
 		if (next1 > line1 || next2 > line2) {
-			struct hashmap submap;
-
-			memset(&submap, 0, sizeof(submap));
 			if (patience_diff(map->file1, map->file2,
 					map->xpp, map->env,
 					line1, next1 - line1,
@@ -323,6 +314,8 @@ static int fall_back_to_classic_diff(str
 		int line1, int count1, int line2, int count2)
 {
 	xpparam_t xpp;
+
+	memset(&xpp, 0, sizeof(xpp));
 	xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
 
 	return xdl_fall_back_diff(map->env, &xpp,
@@ -343,7 +336,7 @@ static int patience_diff(mmfile_t *file1
 	struct entry *first;
 	int result = 0;
 
-	// trivial case: one side is empty
+	/* trivial case: one side is empty */
 	if (!count1) {
 		while(count2--)
 			env->xdf2.rchg[line2++ - 1] = 1;
@@ -359,7 +352,7 @@ static int patience_diff(mmfile_t *file1
 			line1, count1, line2, count2))
 		return -1;
 
-	// are there any matching lines at all?
+	/* are there any matching lines at all? */
 	if (!map.has_matches) {
 		while(count1--)
 			env->xdf1.rchg[line1++ - 1] = 1;
@@ -387,7 +380,7 @@ int xdl_do_patience_diff(mmfile_t *file1
 	if (xdl_prepare_env(file1, file2, xpp, env) < 0)
 		return -1;
 
-	// environment is cleaned up in xdl_diff()
+	/* environment is cleaned up in xdl_diff() */
 	return patience_diff(file1, file2, xpp, env,
 			1, env->xdf1.nrec, 1, env->xdf2.nrec);
 }