autoconf-patches
[Top][All Lists]
Advanced

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

Re: another m4sugar speedup


From: Eric Blake
Subject: Re: another m4sugar speedup
Date: Wed, 3 Oct 2007 23:26:11 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> And here's my next round of optimizations.  AC_SUBST, AC_DEFINE{,_UNQUOTED}, 
> and AS_ESCAPE are the winners this time.  The notion of m4_bpatsubst
(m4_translit
> ()) is just stupid, especially when m4_translit is powerful enough on its own.

Again touching AC_SUBST and AC_DEFINE{,_UNQUOTED} - this is a faster way to 
compute compliance with m4_re_word.

From: Eric Blake <address@hidden>
Date: Wed, 3 Oct 2007 17:18:59 -0600
Subject: [PATCH] Optimize checking for identifiers.

* lib/m4sugar/m4sh.m4 (AS_IDENTIFIER_IF, _AS_IDENTIFIER_IF): New
macros, more efficient than regex on m4_re_word.
* lib/autoconf/general.m4 (AC_SUBST, AC_DEFINE_TRACE_LITERAL):
Rewrite in terms of new macro.  As a side-effect, AC_DEFINE can
now use @&address@hidden
* configure: Regenerate.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog               |    8 ++++++++
 lib/autoconf/general.m4 |    4 ++--
 lib/m4sugar/m4sh.m4     |   28 ++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2b4d535..40d3fb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2007-10-03  Eric Blake  <address@hidden>
 
+       Optimize checking for identifiers.
+       * lib/m4sugar/m4sh.m4 (AS_IDENTIFIER_IF, _AS_IDENTIFIER_IF): New
+       macros, more efficient than regex on m4_re_word.
+       * lib/autoconf/general.m4 (AC_SUBST, AC_DEFINE_TRACE_LITERAL):
+       Rewrite in terms of new macro.  As a side-effect, AC_DEFINE can
+       now use @&address@hidden
+       * configure: Regenerate.
+
        Remove some XFAILs, and make AT_SETUP output line up.
        * lib/autotest/general.m4 (AT_SETUP): Only expand description
        once; thereafter, use its expansion, properly quoted.
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index ecbbe99..df501ec 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -1998,7 +1998,7 @@ AC_DEFUN([_AC_CACHE_CHECK_INT],
 # Used by --trace to collect the list of AC_DEFINEd macros.
 m4_define([AC_DEFINE_TRACE_LITERAL],
 [m4_pattern_allow([^$1$])dnl
-m4_bmatch([$1], ^m4_defn([m4_re_word])$, [],
+AS_IDENTIFIER_IF([$1], [],
   [m4_warn([syntax], [AC_DEFINE: not an identifier: $1])])dnl
 ])# AC_DEFINE_TRACE_LITERAL
 
@@ -2060,7 +2060,7 @@ m4_define([AC_SUBST_TRACE])
 # empty value, not an empty second argument.
 #
 m4_define([AC_SUBST],
-[m4_bmatch(m4_bpatsubst([[$1]], [@&address@hidden), ^m4_defn([m4_re_word])$, 
[],
+[AS_IDENTIFIER_IF([$1], [],
   [AC_FATAL([$0: `$1' is not a valid shell variable name])])dnl
 AC_SUBST_TRACE([$1])dnl
 m4_pattern_allow([^$1$])dnl
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index b8d5c54..025934d 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -1226,6 +1226,34 @@ m4_popdef([AS_Prefix])dnl
 ])# AS_HELP_STRING
 
 
+# AS_IDENTIFIER_IF(EXPRESSION, IF-IDENT, IF-NOT-IDENT)
+# ----------------------------------------------------
+# If EXPRESSION serves as an identifier (ie, after removal of @&t@, it
+# matches the regex `^[a-zA-Z_][a-zA-Z_0-9]*$'), execute IF-IDENT,
+# otherwise IF-NOT-IDENT.
+#
+# This is generally faster than the alternative:
+#   m4_bmatch(m4_bpatsubst([[$1]], [@&address@hidden), ^m4_defn([m4_re_word])$,
+#             [$2], [$3])
+#
+# Rather than expand m4_defn every time AS_IDENTIFIER_IF is expanded, we
+# inline its expansion up front.  Only use a regular expression if we
+# detect a potential quadrigraph.
+#
+# First, check if the entire string matches m4_cr_symbol2.  Only then do
+# we worry if the first character also matches m4_cr_symbol1 (ie. does not
+# match m4_cr_digit).
+m4_define([AS_IDENTIFIER_IF],
+[m4_if(m4_index([$1], address@hidden), [-1],
+       [_$0($@)],
+       [_$0(m4_bpatsubst([[$1]], [@&address@hidden), [$2], [$3])])])
+m4_define([_AS_IDENTIFIER_IF],
+[m4_if([$1], [], [$3],
+       m4_translit([$1], ]m4_dquote(m4_defn([m4_cr_symbols2]))[), [],
+       [m4_if(m4_len(m4_translit(m4_format([[%.1s]], [$1]), ]]dnl
+m4_dquote(m4_dquote(m4_defn([m4_cr_symbols1])))[[)), [0], [$2], [$3])],
+       [$3])])
+
 # AS_LITERAL_IF(EXPRESSION, IF-LITERAL, IF-NOT-LITERAL)
 # -----------------------------------------------------
 # If EXPRESSION has shell indirections ($var or `expr`), expand
-- 
1.5.3.2








reply via email to

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