To: vim_dev@googlegroups.com Subject: Patch 8.0.1046 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1046 Problem: Code duplication in diff mode. Solution: Use diff_equal_char() also in diff_cmp(). (Rick Howe) Files: src/diff.c *** ../vim-8.0.1045/src/diff.c 2017-09-02 18:01:46.422018216 +0200 --- src/diff.c 2017-09-03 15:03:52.784327027 +0200 *************** *** 1661,1666 **** --- 1661,1700 ---- } /* + * 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,1718 **** } else { ! #ifdef FEAT_MBYTE ! l = (*mb_ptr2len)(p1); ! if (l != (*mb_ptr2len)(p2)) 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; ! } } } --- 1723,1732 ---- } else { ! if (!diff_equal_char(p1, p2, &l)) break; ! p1 += l; ! p2 += l; } } *************** *** 1950,1989 **** } /* - * 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. */ --- 1964,1969 ---- *** ../vim-8.0.1045/src/version.c 2017-09-03 14:30:58.229077337 +0200 --- src/version.c 2017-09-03 15:02:27.188879430 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 1046, /**/ -- hundred-and-one symptoms of being an internet addict: 58. You turn on your computer and turn off your wife. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///