diff options
author | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-08-10 17:13:02 -0400 |
---|---|---|
committer | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-08-11 14:54:39 -0400 |
commit | fd334ec2a8109aee71fa11697f4608de76144df8 (patch) | |
tree | 746917cad9643529121fb455eb45574648d24bd8 /src/nvim/diff.c | |
parent | 4f93d05d3985d90701fa9dace22daee82b4e48f9 (diff) | |
download | rneovim-fd334ec2a8109aee71fa11697f4608de76144df8.tar.gz rneovim-fd334ec2a8109aee71fa11697f4608de76144df8.tar.bz2 rneovim-fd334ec2a8109aee71fa11697f4608de76144df8.zip |
vim-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)
https://github.com/vim/vim/commit/ae96b8d058cffd9d07b78cb7a9ccd382185b9dd6
Diffstat (limited to 'src/nvim/diff.c')
-rw-r--r-- | src/nvim/diff.c | 84 |
1 files changed, 33 insertions, 51 deletions
diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7b06609fc3..8dc9d0ee10 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -1597,6 +1597,35 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2) return true; } +// 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 bool diff_equal_char(const char_u *const p1, const char_u *const p2, + int *const len) +{ + const int l = utfc_ptr2len(p1); + + if (l != utfc_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 { + 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. /// @@ -1623,30 +1652,12 @@ static int diff_cmp(char_u *s1, char_u *s2) p1 = skipwhite(p1); p2 = skipwhite(p2); } else { - int l = (*mb_ptr2len)(p1); - if (l != (*mb_ptr2len)(p2)) { + int l; + 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 { - if ((*p1 != *p2) - && (!(diff_flags & DIFF_ICASE) - || (TOLOWER_LOC(*p1) != TOLOWER_LOC(*p2)))) { - break; - } - ++p1; - ++p2; - } + p1 += l; + p2 += l; } } @@ -1870,35 +1881,6 @@ bool diffopt_horizontal(void) return (diff_flags & DIFF_HORIZONTAL) != 0; } -// 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 bool diff_equal_char(const char_u *const p1, const char_u *const p2, - int *const len) -{ - const int l = utfc_ptr2len(p1); - - if (l != utfc_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 { - 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. /// /// @param wp window whose current buffer to check |