This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=34c149521d0b019006ca1737ef0aadbb9294ef00

The branch, master has been updated
       via  34c149521d0b019006ca1737ef0aadbb9294ef00 (commit)
      from  0c5bd94cc2192fc2ab112caf4259abfb9c93cdfe (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 34c149521d0b019006ca1737ef0aadbb9294ef00
Author: Eric Blake <[EMAIL PROTECTED]>
Date:   Sat Sep 29 19:31:06 2007 -0600

    Optimize for Autoconf usage pattern.
    
    * modules/gnu.c (regexp, patsubst): Handle empty regex faster.
    
    Signed-off-by: Eric Blake <[EMAIL PROTECTED]>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog     |    3 +++
 modules/gnu.c |   37 ++++++++++++++++++++++++++++++-------
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fdef1c0..2c31728 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2007-09-29  Eric Blake  <[EMAIL PROTECTED]>
 
+       Optimize for Autoconf usage pattern.
+       * modules/gnu.c (regexp, patsubst): Handle empty regex faster.
+
        * tests/testsuite.at (AT_CHECK_M4): Slight optimization.
 
 2007-09-24  Eric Blake  <[EMAIL PROTECTED]>
diff --git a/modules/gnu.c b/modules/gnu.c
index 9d32638..900ae15 100644
--- a/modules/gnu.c
+++ b/modules/gnu.c
@@ -646,10 +646,14 @@ M4BUILTIN_HANDLER (mkdtemp)
 M4BUILTIN_HANDLER (patsubst)
 {
   const char *me;              /* name of this macro */
+  const char *pattern;         /* regular expression */
+  const char *replace;         /* replacement */
   m4_pattern_buffer *buf;      /* compiled regular expression */
   int resyntax;
 
   me = M4ARG (0);
+  pattern = M4ARG (2);
+  replace = M4ARG (3);
 
   resyntax = m4_get_regexp_syntax_opt (context);
   if (argc >= 5)               /* additional args ignored */
@@ -659,12 +663,21 @@ M4BUILTIN_HANDLER (patsubst)
        return;
     }
 
-  buf = m4_regexp_compile (context, me, M4ARG (2), resyntax, false);
+  /* The empty regex matches everywhere, but if there is no
+     replacement, we need not waste time with it.  */
+  if (!*pattern && !*replace)
+    {
+      const char *str = M4ARG (1);
+      obstack_grow (obs, str, strlen (str));
+      return;
+    }
+
+  buf = m4_regexp_compile (context, me, pattern, resyntax, false);
   if (!buf)
     return;
 
-  m4_regexp_substitute (context, obs, me, M4ARG (1), M4ARG (2), buf,
-                       M4ARG (3), false);
+  m4_regexp_substitute (context, obs, me, M4ARG (1), pattern, buf,
+                       replace, false);
 }
 
 
@@ -680,6 +693,7 @@ M4BUILTIN_HANDLER (patsubst)
 M4BUILTIN_HANDLER (regexp)
 {
   const char *me;              /* name of this macro */
+  const char *pattern;         /* regular expression */
   const char *replace;         /* optional replacement string */
   m4_pattern_buffer *buf;      /* compiled regular expression */
   int startpos;                        /* start position of match */
@@ -687,6 +701,7 @@ M4BUILTIN_HANDLER (regexp)
   int resyntax;
 
   me = M4ARG (0);
+  pattern = M4ARG (2);
   replace = M4ARG (3);
   resyntax = m4_get_regexp_syntax_opt (context);
 
@@ -716,7 +731,17 @@ M4BUILTIN_HANDLER (regexp)
     /* regexp(VICTIM, REGEXP)  */
     replace = NULL;
 
-  buf = m4_regexp_compile (context, me, M4ARG (2), resyntax, replace == NULL);
+  if (!*pattern)
+    {
+      /* The empty regex matches everything.  */
+      if (replace)
+       obstack_grow (obs, replace, strlen (replace));
+      else
+       m4_shipout_int (obs, 0);
+      return;
+    }
+
+  buf = m4_regexp_compile (context, me, pattern, resyntax, replace == NULL);
   if (!buf)
     return;
 
@@ -726,7 +751,7 @@ M4BUILTIN_HANDLER (regexp)
   if (startpos == -2)
     {
       m4_error (context, 0, 0, _("%s: error matching regular expression `%s'"),
-               me, M4ARG (2));
+               me, pattern);
       return;
     }
 
@@ -734,8 +759,6 @@ M4BUILTIN_HANDLER (regexp)
     m4_shipout_int (obs, startpos);
   else if (startpos >= 0)
     substitute (context, obs, me, M4ARG (1), replace, buf);
-
-  return;
 }
 
 


hooks/post-receive
--
GNU M4 source repository


Reply via email to