]> code.delx.au - gnu-emacs/commitdiff
(compile_pattern): Only check `cp->syntax_table' if needed.
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 Oct 2006 13:25:26 +0000 (13:25 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 Oct 2006 13:25:26 +0000 (13:25 +0000)
(compile_pattern_1): Remember `used_syntax' in `cp->syntax_table'.

src/search.c

index e26b8f883e1f6aa9b80b5a2ffdf21b538281de22..5f9f321067a9fbceaca6e3a64e433ccfa7154ea2 100644 (file)
@@ -43,7 +43,8 @@ struct regexp_cache
   struct regexp_cache *next;
   Lisp_Object regexp, whitespace_regexp;
   /* Syntax table for which the regexp applies.  We need this because
-     of character classes.  */
+     of character classes.  If this is t, then the compiled pattern is valid
+     for any syntax-table.  */
   Lisp_Object syntax_table;
   struct re_pattern_buffer buf;
   char fastmap[0400];
@@ -170,7 +171,6 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
   cp->posix = posix;
   cp->buf.multibyte = multibyte;
   cp->whitespace_regexp = Vsearch_spaces_regexp;
-  cp->syntax_table = current_buffer->syntax_table;
   /* rms: I think BLOCK_INPUT is not needed here any more,
      because regex.c defines malloc to call xmalloc.
      Using BLOCK_INPUT here means the debugger won't run if an error occurs.
@@ -185,6 +185,10 @@ compile_pattern_1 (cp, pattern, translate, regp, posix, multibyte)
   val = (char *) re_compile_pattern ((char *)raw_pattern,
                                     raw_pattern_size, &cp->buf);
 
+  /* If the compiled pattern hard codes some of the contents of the
+     syntax-table, it can only be reused with *this* syntax table.  */
+  cp->syntax_table = cp->buf.used_syntax ? current_buffer->syntax_table : Qt;
+
   re_set_whitespace_regexp (NULL);
 
   re_set_syntax (old);
@@ -261,10 +265,8 @@ compile_pattern (pattern, regp, translate, posix, multibyte)
          && EQ (cp->buf.translate, (! NILP (translate) ? translate : make_number (0)))
          && cp->posix == posix
          && cp->buf.multibyte == multibyte
-         /* TODO: Strictly speaking, we only need to match syntax
-            tables when a character class like [[:space:]] occurs in
-            the pattern. -- cyd*/
-         && EQ (cp->syntax_table, current_buffer->syntax_table)
+         && (EQ (cp->syntax_table, Qt)
+             || EQ (cp->syntax_table, current_buffer->syntax_table))
          && !NILP (Fequal (cp->whitespace_regexp, Vsearch_spaces_regexp)))
        break;