changeset 12333:dea5dda9ef30 v8.0.1046

patch 8.0.1046: code duplication in diff mode commit https://github.com/vim/vim/commit/ae96b8d058cffd9d07b78cb7a9ccd382185b9dd6 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 3 15:04:21 2017 +0200 patch 8.0.1046: code duplication in diff mode Problem: Code duplication in diff mode. Solution: Use diff_equal_char() also in diff_cmp(). (Rick Howe)
author Christian Brabandt <cb@256bit.org>
date Sun, 03 Sep 2017 15:15:05 +0200
parents dd6f3bfdebaa
children 807044c2bd36
files src/diff.c src/version.c
diffstat 2 files changed, 39 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/diff.c
+++ b/src/diff.c
@@ -1661,6 +1661,40 @@ diff_equal_entry(diff_T *dp, int idx1, i
 }
 
 /*
+ * Compare the characters at "p1" and "p2".  If they are equal (possibly
+ * ignoring case) return TRUE and set "len" to the number of bytes.
+ */
+    static int
+diff_equal_char(char_u *p1, char_u *p2, int *len)
+{
+#ifdef FEAT_MBYTE
+    int l  = (*mb_ptr2len)(p1);
+
+    if (l != (*mb_ptr2len)(p2))
+	return FALSE;
+    if (l > 1)
+    {
+	if (STRNCMP(p1, p2, l) != 0
+		&& (!enc_utf8
+		    || !(diff_flags & DIFF_ICASE)
+		    || utf_fold(utf_ptr2char(p1))
+						!= utf_fold(utf_ptr2char(p2))))
+	    return FALSE;
+	*len = l;
+    }
+    else
+#endif
+    {
+	if ((*p1 != *p2)
+		&& (!(diff_flags & DIFF_ICASE)
+		    || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))
+	    return FALSE;
+	*len = 1;
+    }
+    return TRUE;
+}
+
+/*
  * Compare strings "s1" and "s2" according to 'diffopt'.
  * Return non-zero when they are different.
  */
@@ -1689,30 +1723,10 @@ diff_cmp(char_u *s1, char_u *s2)
 	}
 	else
 	{
-#ifdef FEAT_MBYTE
-	    l  = (*mb_ptr2len)(p1);
-	    if (l != (*mb_ptr2len)(p2))
+	    if (!diff_equal_char(p1, p2, &l))
 		break;
-	    if (l > 1)
-	    {
-		if (STRNCMP(p1, p2, l) != 0
-			&& (!enc_utf8
-			    || !(diff_flags & DIFF_ICASE)
-			    || utf_fold(utf_ptr2char(p1))
-					       != utf_fold(utf_ptr2char(p2))))
-		    break;
-		p1 += l;
-		p2 += l;
-	    }
-	    else
-#endif
-	    {
-		if (*p1 != *p2 && (!(diff_flags & DIFF_ICASE)
-				     || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))
-		    break;
-		++p1;
-		++p2;
-	    }
+	    p1 += l;
+	    p2 += l;
 	}
     }
 
@@ -1950,40 +1964,6 @@ diffopt_horizontal(void)
 }
 
 /*
- * Compare the characters at "p1" and "p2".  If they are equal (possibly
- * ignoring case) return TRUE and set "len" to the number of bytes.
- */
-    static int
-diff_equal_char(char_u *p1, char_u *p2, int *len)
-{
-#ifdef FEAT_MBYTE
-    int l  = (*mb_ptr2len)(p1);
-
-    if (l != (*mb_ptr2len)(p2))
-	return FALSE;
-    if (l > 1)
-    {
-	if (STRNCMP(p1, p2, l) != 0
-		&& (!enc_utf8
-		    || !(diff_flags & DIFF_ICASE)
-		    || utf_fold(utf_ptr2char(p1))
-						!= utf_fold(utf_ptr2char(p2))))
-	    return FALSE;
-	*len = l;
-    }
-    else
-#endif
-    {
-	if ((*p1 != *p2)
-		&& (!(diff_flags & DIFF_ICASE)
-		    || TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))
-	    return FALSE;
-	*len = 1;
-    }
-    return TRUE;
-}
-
-/*
  * Find the difference within a changed line.
  * Returns TRUE if the line was added, no other buffer has it.
  */
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1046,
+/**/
     1045,
 /**/
     1044,