aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1998-04-29 06:50:40 +0000
committerRichard M. Stallman1998-04-29 06:50:40 +0000
commit07422a1266e24464c8570cc77416d94604c110ed (patch)
treef057fe95663c8734cbbddc99e7effe32336511b2 /src
parentc18404773b57b6f96230a0268e5fedf27ffa64b9 (diff)
downloademacs-07422a1266e24464c8570cc77416d94604c110ed.tar.gz
emacs-07422a1266e24464c8570cc77416d94604c110ed.zip
(Fcompare_buffer_substrings): Rewrite to loop by chars.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c60
1 files changed, 39 insertions, 21 deletions
diff --git a/src/editfns.c b/src/editfns.c
index b3e744b3477..bfee7325df8 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1686,13 +1686,13 @@ determines whether case is significant or ignored.")
1686 (buffer1, start1, end1, buffer2, start2, end2) 1686 (buffer1, start1, end1, buffer2, start2, end2)
1687 Lisp_Object buffer1, start1, end1, buffer2, start2, end2; 1687 Lisp_Object buffer1, start1, end1, buffer2, start2, end2;
1688{ 1688{
1689 register int begp1, endp1, begp2, endp2, temp, len1, len2, length, i; 1689 register int begp1, endp1, begp2, endp2, temp;
1690 register struct buffer *bp1, *bp2; 1690 register struct buffer *bp1, *bp2;
1691 register Lisp_Object *trt 1691 register Lisp_Object *trt
1692 = (!NILP (current_buffer->case_fold_search) 1692 = (!NILP (current_buffer->case_fold_search)
1693 ? XCHAR_TABLE (current_buffer->case_canon_table)->contents : 0); 1693 ? XCHAR_TABLE (current_buffer->case_canon_table)->contents : 0);
1694 int chars = 0; 1694 int chars = 0;
1695 int beg1_byte, beg2_byte; 1695 int i1, i2, i1_byte, i2_byte;
1696 1696
1697 /* Find the first buffer and its substring. */ 1697 /* Find the first buffer and its substring. */
1698 1698
@@ -1770,26 +1770,42 @@ determines whether case is significant or ignored.")
1770 && endp2 <= BUF_ZV (bp2))) 1770 && endp2 <= BUF_ZV (bp2)))
1771 args_out_of_range (start2, end2); 1771 args_out_of_range (start2, end2);
1772 1772
1773 beg1_byte = buf_charpos_to_bytepos (bp1, begp1); 1773 i1 = begp1;
1774 beg2_byte = buf_charpos_to_bytepos (bp2, begp2); 1774 i2 = begp2;
1775 len1 = buf_charpos_to_bytepos (bp1, endp1) - begp1; 1775 i1_byte = buf_charpos_to_bytepos (bp1, i1);
1776 len2 = buf_charpos_to_bytepos (bp2, endp2) - begp2; 1776 i2_byte = buf_charpos_to_bytepos (bp2, i2);
1777 length = len1;
1778 if (len2 < length)
1779 length = len2;
1780 1777
1781 for (i = 0; i < length; i++) 1778 while (i1 < endp1 && i2 < endp2)
1782 { 1779 {
1783 unsigned char *p1 = BUF_BYTE_ADDRESS (bp1, beg1_byte + i); 1780 /* When we find a mismatch, we must compare the
1784 int c1 = *p1; 1781 characters, not just the bytes. */
1785 int c2 = *BUF_BYTE_ADDRESS (bp2, beg2_byte + i); 1782 int c1, c2;
1786 1783
1787 /* If a character begins here, 1784 if (! NILP (bp1->enable_multibyte_characters))
1788 count the previous character now. */ 1785 {
1789 if (i > 0 1786 c1 = BUF_FETCH_MULTIBYTE_CHAR (bp1, i1_byte);
1790 && (NILP (current_buffer->enable_multibyte_characters) 1787 BUF_INC_POS (bp1, i1_byte);
1791 || CHAR_HEAD_P (*p1))) 1788 i1++;
1792 chars++; 1789 }
1790 else
1791 {
1792 c1 = BUF_FETCH_BYTE (bp1, i1);
1793 c1 = unibyte_char_to_multibyte (c1);
1794 i1++;
1795 }
1796
1797 if (! NILP (bp2->enable_multibyte_characters))
1798 {
1799 c2 = BUF_FETCH_MULTIBYTE_CHAR (bp2, i2_byte);
1800 BUF_INC_POS (bp2, i2_byte);
1801 i2++;
1802 }
1803 else
1804 {
1805 c2 = BUF_FETCH_BYTE (bp2, i2);
1806 c2 = unibyte_char_to_multibyte (c2);
1807 i2++;
1808 }
1793 1809
1794 if (trt) 1810 if (trt)
1795 { 1811 {
@@ -1800,13 +1816,15 @@ determines whether case is significant or ignored.")
1800 return make_number (- 1 - chars); 1816 return make_number (- 1 - chars);
1801 if (c1 > c2) 1817 if (c1 > c2)
1802 return make_number (chars + 1); 1818 return make_number (chars + 1);
1819
1820 chars++;
1803 } 1821 }
1804 1822
1805 /* The strings match as far as they go. 1823 /* The strings match as far as they go.
1806 If one is shorter, that one is less. */ 1824 If one is shorter, that one is less. */
1807 if (length < len1) 1825 if (chars < endp1 - begp1)
1808 return make_number (chars + 1); 1826 return make_number (chars + 1);
1809 else if (length < len2) 1827 else if (chars < endp2 - begp2)
1810 return make_number (- chars - 1); 1828 return make_number (- chars - 1);
1811 1829
1812 /* Same length too => they are equal. */ 1830 /* Same length too => they are equal. */