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. 000a6507a4ab


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, branch-1_4, updated. 000a6507a4ab5b46a609efc6fc5152e34c86e095
Date: Mon, 01 Oct 2007 21:39:50 +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=000a6507a4ab5b46a609efc6fc5152e34c86e095

The branch, branch-1_4 has been updated
       via  000a6507a4ab5b46a609efc6fc5152e34c86e095 (commit)
      from  aa46ced67010190918295b965f5e2879dcd9a30c (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 000a6507a4ab5b46a609efc6fc5152e34c86e095
Author: Eric Blake <address@hidden>
Date:   Mon Oct 1 14:30:25 2007 -0600

    Another Autoconf usage pattern optimization.
    
    * src/builtin.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 ++++++++++++++++++---
 src/builtin.c  |   19 +++++++++++++++----
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f29b557..396a64f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-01  Eric Blake  <address@hidden>
+
+       Another Autoconf usage pattern optimization.
+       * src/builtin.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 a24d36e..6c76b7b 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -4610,12 +4610,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: too few arguments to builtin `index'
 @result{}0
+index(`abc', `')
address@hidden
+index(`abc', `b')
address@hidden
 @end example
 
 @node Regexp
@@ -4688,12 +4693,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: too few arguments to builtin `regexp'
 @result{}0
+regexp(`abc', `')
address@hidden
+regexp(`abc', `', `def')
address@hidden
 @end example
 
 @node Substr
@@ -4904,12 +4914,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: too few arguments to builtin `patsubst'
 @result{}abc
+patsubst(`abc', `')
address@hidden
+patsubst(`abc', `', `-')
address@hidden
 @end example
 
 @node Format
diff --git a/src/builtin.c b/src/builtin.c
index 65f4585..8974b1a 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1677,8 +1677,9 @@ static void
 m4_index (struct obstack *obs, int argc, token_data **argv)
 {
   const char *haystack;
-  const char *result;
-  int retval;
+  const char *needle;
+  const char *result = NULL;
+  int retval = -1;
 
   if (bad_argc (argv[0], argc, 3, 3))
     {
@@ -1689,8 +1690,18 @@ m4_index (struct obstack *obs, int argc, token_data 
**argv)
     }
 
   haystack = ARG (1);
-  result = strstr (haystack, ARG (2));
-  retval = result ? result - haystack : -1;
+  needle = ARG (2);
+
+  /* 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;
 
   shipout_int (obs, retval);
 }


hooks/post-receive
--
GNU M4 source repository




reply via email to

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