]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Optimize checking for identifiers.
authorEric Blake <ebb9@byu.net>
Wed, 3 Oct 2007 23:18:59 +0000 (17:18 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 3 Oct 2007 23:22:46 +0000 (17:22 -0600)
* 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 @&t@.
* configure: Regenerate.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
configure
lib/autoconf/general.m4
lib/m4sugar/m4sh.m4

index 2b4d535306c00571c35c3df2c2e4c0e2a95c1567..40d3fb834d25c724c81de9174ab3c33eb93d3e4b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2007-10-03  Eric Blake  <ebb9@byu.net>
 
+       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 @&t@.
+       * 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.
index 434301a82a28bd16fb442dfdd9d9d8488f542db2..2cc27fb02b03a8c31361fbd58efa547e20a109ff 100755 (executable)
--- a/configure
+++ b/configure
@@ -373,10 +373,10 @@ fi
 
       if test "x$CONFIG_SHELL" != x; then
   for as_var in BASH_ENV ENV
-        do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
-        done
-        export CONFIG_SHELL
-        exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+       do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+       done
+       export CONFIG_SHELL
+       exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
 fi
 
 
@@ -561,10 +561,10 @@ else
   as_test_x='
     eval sh -c '\''
       if test -d "$1"; then
-        test -d "$1/.";
+       test -d "$1/.";
       else
        case $1 in
-        -*)set "./$1";;
+       -*)set "./$1";;
        esac;
        case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
        ???[sx]*):;;*)false;;esac;fi
@@ -3307,10 +3307,10 @@ else
   as_test_x='
     eval sh -c '\''
       if test -d "$1"; then
-        test -d "$1/.";
+       test -d "$1/.";
       else
        case $1 in
-        -*)set "./$1";;
+       -*)set "./$1";;
        esac;
        case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
        ???[sx]*):;;*)false;;esac;fi
index ecbbe996c28ef7d49387bb5abf4a36f1ff380a3d..df501ec43f53ff5dd37de113f177f4e0359e15a6 100644 (file)
@@ -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]], [@&t@]), ^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
index b8d5c548c81973009759c8d3837f716b2505ed6b..025934d84495f41811354256c24fc9c8755e3f40 100644 (file)
@@ -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]], [@&t@]), ^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], [@]), [-1],
+       [_$0($@)],
+       [_$0(m4_bpatsubst([[$1]], [@&t@]), [$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