m4-commit
[Top][All Lists]
Advanced

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

[SCM] GNU M4 source repository branch, master, updated. 8b55caca720db14c


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, master, updated. 8b55caca720db14c67afcbc78294d56a02a0e6a0
Date: Mon, 01 Oct 2007 22:40:20 +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=8b55caca720db14c67afcbc78294d56a02a0e6a0

The branch, master has been updated
       via  8b55caca720db14c67afcbc78294d56a02a0e6a0 (commit)
      from  34c149521d0b019006ca1737ef0aadbb9294ef00 (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 8b55caca720db14c67afcbc78294d56a02a0e6a0
Author: Eric Blake <address@hidden>
Date:   Mon Oct 1 16:40:12 2007 -0600

    Another Autoconf usage pattern optimization.
    
    * modules/m4.c (m4_index): Optimize search for one byte.
    * doc/m4.texinfo (Index macro, Regexp, Patsubst): Test the new
    code paths.
    
    Signed-off-by: Eric Blake <address@hidden>

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

Summary of changes:
 ChangeLog      |    7 +++++++
 doc/m4.texinfo |   21 ++++++++++++++++++---
 modules/m4.c   |   16 ++++++++++++++--
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2c31728..307a697 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-01  Eric Blake  <address@hidden>
+
+       Another Autoconf usage pattern optimization.
+       * modules/m4.c (m4_index): Optimize search for one byte.
+       * doc/m4.texinfo (Index macro, Regexp, Patsubst): Test the new
+       code paths.
+
 2007-09-29  Eric Blake  <address@hidden>
 
        Optimize for Autoconf usage pattern.
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index 844d48a..b5dc467 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -5749,12 +5749,17 @@ index(`gnus, gnats, and armadillos', `dag')
 @result{}-1
 @end example
 
-Omitting @var{substring} evokes a warning, but still produces output.
+Omitting @var{substring} evokes a warning, but still produces output;
+contrast this with an empty @var{substring}.
 
 @example
 index(`abc')
 @error{}m4:stdin:1: Warning: index: too few arguments: 1 < 2
 @result{}0
+index(`abc', `')
address@hidden
+index(`abc', `b')
address@hidden
 @end example
 
 @node Regexp
@@ -5822,12 +5827,17 @@ regexp(`abc', `\(\(d\)?\)\(c\)', `\1\2\3\4\5\6')
 @result{}c
 @end example
 
-Omitting @var{regexp} evokes a warning, but still produces output.
+Omitting @var{regexp} evokes a warning, but still produces output;
+contrast this with an empty @var{regexp} argument.
 
 @example
 regexp(`abc')
 @error{}m4:stdin:1: Warning: regexp: too few arguments: 1 < 2
 @result{}0
+regexp(`abc', `')
address@hidden
+regexp(`abc', `', `def')
address@hidden
 @end example
 
 If @var{resyntax} is given, @var{regexp} must be given according to
@@ -6078,12 +6088,17 @@ patreg(`aba abb 121', `\(.\)\(.\)\1', `\2\1\2')
 @result{}bab
 @end example
 
-Omitting @var{regexp} evokes a warning, but still produces output.
+Omitting @var{regexp} evokes a warning, but still produces output;
+contrast this with an empty @var{regexp} argument.
 
 @example
 patsubst(`abc')
 @error{}m4:stdin:1: Warning: patsubst: too few arguments: 1 < 2
 @result{}abc
+patsubst(`abc', `')
address@hidden
+patsubst(`abc', `', `-')
address@hidden
 @end example
 
 @node Format
diff --git a/modules/m4.c b/modules/m4.c
index eef3a61..b39c5f2 100644
--- a/modules/m4.c
+++ b/modules/m4.c
@@ -913,8 +913,20 @@ M4BUILTIN_HANDLER (len)
 M4BUILTIN_HANDLER (index)
 {
   const char *haystack = M4ARG (1);
-  const char *result = strstr (haystack, M4ARG (2));
-  int retval = result ? result - haystack : -1;
+  const char *needle = M4ARG (2);
+  const char *result = NULL;
+  int retval = -1;
+
+  /* Optimize searching for the empty string (always 0) and one byte
+     (strchr tends to be more efficient than strstr).  */
+  if (!needle[0])
+    retval = 0;
+  else if (!needle[1])
+    result = strchr (haystack, *needle);
+  else
+    result = strstr (haystack, needle);
+  if (result)
+    retval = result - haystack;
 
   m4_shipout_int (obs, retval);
 }


hooks/post-receive
--
GNU M4 source repository




reply via email to

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