aboutsummaryrefslogtreecommitdiffstats
path: root/src/search.c
diff options
context:
space:
mode:
authorAndreas Schwab2009-11-22 12:11:00 +0000
committerAndreas Schwab2009-11-22 12:11:00 +0000
commit8b264ecb46019f91a474bfa1dcd5b86c1949c102 (patch)
treeaf09e56670a3a4134e158835bfb8d65994d6dccc /src/search.c
parent433d9ace74fbd35205c06bcef487bd3e5d41e6bb (diff)
downloademacs-8b264ecb46019f91a474bfa1dcd5b86c1949c102.tar.gz
emacs-8b264ecb46019f91a474bfa1dcd5b86c1949c102.zip
(simple_search): Avoid CHAR_TO_BYTE in inner loop when
searching backwards through multibyte buffer.
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/search.c b/src/search.c
index fd45d316a46..abbad764c3c 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1609,39 +1609,36 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
1609 while (1) 1609 while (1)
1610 { 1610 {
1611 /* Try matching at position POS. */ 1611 /* Try matching at position POS. */
1612 EMACS_INT this_pos = pos - len; 1612 EMACS_INT this_pos = pos;
1613 EMACS_INT this_pos_byte; 1613 EMACS_INT this_pos_byte = pos_byte;
1614 int this_len = len; 1614 int this_len = len;
1615 unsigned char *p = pat; 1615 unsigned char *p = pat + len_byte;
1616 1616
1617 if (this_pos < lim || (pos_byte - len_byte) < lim_byte) 1617 if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte)
1618 goto stop; 1618 goto stop;
1619 this_pos_byte = CHAR_TO_BYTE (this_pos);
1620 match_byte = pos_byte - this_pos_byte;
1621 1619
1622 while (this_len > 0) 1620 while (this_len > 0)
1623 { 1621 {
1624 int charlen, buf_charlen; 1622 int charlen;
1625 int pat_ch, buf_ch; 1623 int pat_ch, buf_ch;
1626 1624
1627 pat_ch = STRING_CHAR_AND_LENGTH (p, charlen); 1625 DEC_BOTH (this_pos, this_pos_byte);
1628 buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte), 1626 PREV_CHAR_BOUNDARY (p, pat);
1629 buf_charlen); 1627 pat_ch = STRING_CHAR (p);
1628 buf_ch = STRING_CHAR (BYTE_POS_ADDR (this_pos_byte));
1630 TRANSLATE (buf_ch, trt, buf_ch); 1629 TRANSLATE (buf_ch, trt, buf_ch);
1631 1630
1632 if (buf_ch != pat_ch) 1631 if (buf_ch != pat_ch)
1633 break; 1632 break;
1634 1633
1635 this_len--; 1634 this_len--;
1636 p += charlen;
1637 this_pos_byte += buf_charlen;
1638 this_pos++;
1639 } 1635 }
1640 1636
1641 if (this_len == 0) 1637 if (this_len == 0)
1642 { 1638 {
1643 pos -= len; 1639 match_byte = pos_byte - this_pos_byte;
1644 pos_byte -= match_byte; 1640 pos = this_pos;
1641 pos_byte = this_pos_byte;
1645 break; 1642 break;
1646 } 1643 }
1647 1644