m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU M4 source repository branch, branch-1_4, updated. aa46ced67010


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, branch-1_4, updated. aa46ced67010190918295b965f5e2879dcd9a30c
Date: Sun, 30 Sep 2007 00:00:35 +0000

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=aa46ced67010190918295b965f5e2879dcd9a30c

The branch, branch-1_4 has been updated
       via  aa46ced67010190918295b965f5e2879dcd9a30c (commit)
      from  e3b90fb678b610e3d2ee86d1f00e6f20b1eeef29 (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 aa46ced67010190918295b965f5e2879dcd9a30c
Author: Eric Blake <address@hidden>
Date:   Sat Sep 29 17:48:29 2007 -0600

    Optimize for Autoconf usage pattern.
    
    * src/builtin.c (m4_regexp, m4_patsubst): Handle empty regex
    faster.
    
    Signed-off-by: Eric Blake <address@hidden>

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

Summary of changes:
 ChangeLog     |    6 ++++++
 src/builtin.c |   36 +++++++++++++++++++++++++++---------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0cea5b5..f29b557 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-09-29  Eric Blake  <address@hidden>
+
+       Optimize for Autoconf usage pattern.
+       * src/builtin.c (m4_regexp, m4_patsubst): Handle empty regex
+       faster.
+
 2007-09-24  Eric Blake  <address@hidden>
 
        Create .gitignore alongside .cvsignore.
diff --git a/src/builtin.c b/src/builtin.c
index dee2276..65f4585 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1968,8 +1968,19 @@ m4_regexp (struct obstack *obs, int argc, token_data 
**argv)
       return;
     }
 
-  victim = TOKEN_DATA_TEXT (argv[1]);
-  regexp = TOKEN_DATA_TEXT (argv[2]);
+  victim = ARG (1);
+  regexp = ARG (2);
+  repl = ARG (3);
+
+  if (!*regexp)
+    {
+      /* The empty regex matches everything!  */
+      if (argc == 3)
+       shipout_int (obs, 0);
+      else
+       obstack_grow (obs, repl, strlen (repl));
+      return;
+    }
 
   init_pattern_buffer (&buf, &regs);
   msg = re_compile_pattern (regexp, strlen (regexp), &buf);
@@ -1993,10 +2004,7 @@ m4_regexp (struct obstack *obs, int argc, token_data 
**argv)
   else if (argc == 3)
     shipout_int (obs, startpos);
   else if (startpos >= 0)
-    {
-      repl = TOKEN_DATA_TEXT (argv[3]);
-      substitute (obs, victim, repl, &regs);
-    }
+    substitute (obs, victim, repl, &regs);
 
   free_pattern_buffer (&buf, &regs);
 }
@@ -2013,6 +2021,7 @@ m4_patsubst (struct obstack *obs, int argc, token_data 
**argv)
 {
   const char *victim;          /* first argument */
   const char *regexp;          /* regular expression */
+  const char *repl;
 
   struct re_pattern_buffer buf;        /* compiled regular expression */
   struct re_registers regs;    /* for subexpression matches */
@@ -2029,7 +2038,17 @@ m4_patsubst (struct obstack *obs, int argc, token_data 
**argv)
       return;
     }
 
-  regexp = TOKEN_DATA_TEXT (argv[2]);
+  victim = ARG (1);
+  regexp = ARG (2);
+  repl = ARG (3);
+
+  /* The empty regex matches everywhere, but if there is no
+     replacement, we need not waste time with it.  */
+  if (!*regexp && !*repl)
+    {
+      obstack_grow (obs, victim, strlen (victim));
+      return;
+    }
 
   init_pattern_buffer (&buf, &regs);
   msg = re_compile_pattern (regexp, strlen (regexp), &buf);
@@ -2042,7 +2061,6 @@ m4_patsubst (struct obstack *obs, int argc, token_data 
**argv)
       return;
     }
 
-  victim = TOKEN_DATA_TEXT (argv[1]);
   length = strlen (victim);
 
   offset = 0;
@@ -2073,7 +2091,7 @@ m4_patsubst (struct obstack *obs, int argc, token_data 
**argv)
 
       /* Handle the part of the string that was covered by the match.  */
 
-      substitute (obs, victim, ARG (3), &regs);
+      substitute (obs, victim, repl, &regs);
 
       /* Update the offset to the end of the match.  If the regexp
         matched a null string, advance offset one more, to avoid


hooks/post-receive
--
GNU M4 source repository




reply via email to

[Prev in Thread] Current Thread [Next in Thread]