]> git.eshelyaron.com Git - emacs.git/commitdiff
(simple_search): Avoid CHAR_TO_BYTE in inner loop when
authorAndreas Schwab <schwab@linux-m68k.org>
Sun, 22 Nov 2009 12:11:00 +0000 (12:11 +0000)
committerAndreas Schwab <schwab@linux-m68k.org>
Sun, 22 Nov 2009 12:11:00 +0000 (12:11 +0000)
searching backwards through multibyte buffer.

src/ChangeLog
src/search.c

index 27c2b7246af0a438110dafaa726a9fc472716158..1ac89ec8561e3ac47f4dcc28f8a2275dd15a4b82 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-22  Andreas Schwab  <schwab@linux-m68k.org>
+
+       * search.c (simple_search): Avoid CHAR_TO_BYTE in inner loop when
+       searching backwards through multibyte buffer.
+
 2009-11-21  Jan Djärv  <jan.h.d@swipnet.se>
 
        * xterm.c: #include xgselect.h.
index fd45d316a46d3107b7ed03c915793bc0768acdf6..abbad764c3c41a9ad7b2b62d66e78c701f6a22dc 100644 (file)
@@ -1609,39 +1609,36 @@ simple_search (n, pat, len, len_byte, trt, pos, pos_byte, lim, lim_byte)
        while (1)
          {
            /* Try matching at position POS.  */
-           EMACS_INT this_pos = pos - len;
-           EMACS_INT this_pos_byte;
+           EMACS_INT this_pos = pos;
+           EMACS_INT this_pos_byte = pos_byte;
            int this_len = len;
-           unsigned char *p = pat;
+           unsigned char *p = pat + len_byte;
 
-           if (this_pos < lim || (pos_byte - len_byte) < lim_byte)
+           if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte)
              goto stop;
-           this_pos_byte = CHAR_TO_BYTE (this_pos);
-           match_byte = pos_byte - this_pos_byte;
 
            while (this_len > 0)
              {
-               int charlen, buf_charlen;
+               int charlen;
                int pat_ch, buf_ch;
 
-               pat_ch = STRING_CHAR_AND_LENGTH (p, charlen);
-               buf_ch = STRING_CHAR_AND_LENGTH (BYTE_POS_ADDR (this_pos_byte),
-                                                buf_charlen);
+               DEC_BOTH (this_pos, this_pos_byte);
+               PREV_CHAR_BOUNDARY (p, pat);
+               pat_ch = STRING_CHAR (p);
+               buf_ch = STRING_CHAR (BYTE_POS_ADDR (this_pos_byte));
                TRANSLATE (buf_ch, trt, buf_ch);
 
                if (buf_ch != pat_ch)
                  break;
 
                this_len--;
-               p += charlen;
-               this_pos_byte += buf_charlen;
-               this_pos++;
              }
 
            if (this_len == 0)
              {
-               pos -= len;
-               pos_byte -= match_byte;
+               match_byte = pos_byte - this_pos_byte;
+               pos = this_pos;
+               pos_byte = this_pos_byte;
                break;
              }