Merge from emacs-23
[bpt/emacs.git] / src / search.c
index fd45d31..736a892 100644 (file)
@@ -1,6 +1,6 @@
 /* String search routines for GNU Emacs.
    Copyright (C) 1985, 1986, 1987, 1993, 1994, 1997, 1998, 1999, 2001, 2002,
-                 2003, 2004, 2005, 2006, 2007, 2008, 2009
+                 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -100,10 +100,10 @@ Lisp_Object Vinhibit_changing_match_data;
 
 static void set_search_regs P_ ((EMACS_INT, EMACS_INT));
 static void save_search_regs P_ ((void));
-static EMACS_INT simple_search P_ ((int, unsigned char *, int, int, 
+static EMACS_INT simple_search P_ ((int, unsigned char *, int, int,
                                    Lisp_Object, EMACS_INT, EMACS_INT,
                                    EMACS_INT, EMACS_INT));
-static EMACS_INT boyer_moore P_ ((int, unsigned char *, int, int, 
+static EMACS_INT boyer_moore P_ ((int, unsigned char *, int, int,
                                  Lisp_Object, Lisp_Object,
                                  EMACS_INT, EMACS_INT,
                                  EMACS_INT, EMACS_INT, int));
@@ -281,7 +281,7 @@ compile_pattern (pattern, regp, translate, posix, multibyte)
   if (regp)
     re_set_registers (&cp->buf, regp, regp->num_regs, regp->start, regp->end);
 
-  /* The compiled pattern can be used both for mulitbyte and unibyte
+  /* The compiled pattern can be used both for multibyte and unibyte
      target.  But, we have to tell which the pattern is used for. */
   cp->buf.target_multibyte = multibyte;
 
@@ -582,7 +582,7 @@ fast_looking_at (regexp, pos, pos_byte, limit, limit_byte, string)
   unsigned char *p1, *p2;
   EMACS_INT s1, s2;
   EMACS_INT len;
-  
+
   if (STRINGP (string))
     {
       if (pos_byte < 0)
@@ -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;
+           const 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;
              }