[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 01/12] use a shell function for _AC_PREPROC_IFELSE
From: |
Eric Blake |
Subject: |
Re: [PATCH 01/12] use a shell function for _AC_PREPROC_IFELSE |
Date: |
Tue, 21 Oct 2008 15:13:03 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Paolo Bonzini <bonzini <at> gnu.org> writes:
>
> So, this is the patch bomb for shell functions.
>
> I'm starting from four simple functions for _AC_*_IFELSE. Together,
> they obtain most of the size reduction (10-15%) but slow down Autoconf
> by ~5%.
Slow down? Not on my watch ;)
I'm squashing some changes on top of yours, and then I actually see a speedup
of .5 or 1% (the lost time you were seeing was all the wasted parsing of the
function body and computation of diversion numbers within AS_REQUIRE; now that
the function body is hidden behind a macro name, and AS_REQUIRE is called less
frequently, there is a net gain). Here's what I'm about to push, provided that
the testsuite currently in progress completes successfully.
From: Paolo Bonzini <address@hidden>
Date: Tue, 21 Oct 2008 08:55:05 -0600
Subject: [PATCH] Use a shell function for _AC_PREPROC_IFELSE.
* lib/autoconf/general.m4 (_AC_PREPROC_IFELSE_BODY): New macro.
(_AC_PREPROC_IFELSE): Use a shell function.
* lib/m4sugar/m4sh.m4 (AS_REQUIRE): Factor for faster execution.
* lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): Bypass AS_REQUIRE if
function has already been provided.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 10 ++++++++++
lib/autoconf/general.m4 | 34 ++++++++++++++++++++++++----------
lib/m4sugar/m4sh.m4 | 17 +++++++++++------
3 files changed, 45 insertions(+), 16 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e57150e..e6759f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-21 Paolo Bonzini <address@hidden>
+ and Eric Blake <address@hidden>
+
+ Use a shell function for _AC_PREPROC_IFELSE.
+ * lib/autoconf/general.m4 (_AC_PREPROC_IFELSE_BODY): New macro.
+ (_AC_PREPROC_IFELSE): Use a shell function.
+ * lib/m4sugar/m4sh.m4 (AS_REQUIRE): Factor for faster execution.
+ * lib/m4sugar/m4sh.m4 (AS_REQUIRE_SHELL_FN): Bypass AS_REQUIRE if
+ function has already been provided.
+
2008-10-21 Eric Blake <address@hidden>
Add banners to generated files.
diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4
index 32c13f6..b5c720d 100644
--- a/lib/autoconf/general.m4
+++ b/lib/autoconf/general.m4
@@ -2377,6 +2377,23 @@ AC_DEFUN([AC_RUN_LOG],
## ------------------------ ##
+# _AC_PREPROC_IFELSE_BODY
+# -----------------------
+# Shell function body for _AC_PREPROC_IFELSE.
+m4_define([_AC_PREPROC_IFELSE_BODY],
+[ AS_LINENO_PUSH([$[]1])
+ AS_IF([_AC_DO_STDERR([$ac_cpp conftest.$ac_ext]) >/dev/null && {
+ test -z "$ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag$ac_[]_AC_LANG_ABBREV
[]_werror_flag" ||
+ test ! -s conftest.err
+ }],
+ [ac_retval=0],
+ [_AC_MSG_LOG_CONFTEST
+ ac_retval=1])
+ rm -f conftest.err
+ AS_LINENO_POP
+ return $ac_retval
+])
+
# _AC_PREPROC_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ----------------------------------------------------------------
@@ -2385,18 +2402,15 @@ AC_DEFUN([AC_RUN_LOG],
# This macro can be used during the selection of a preprocessor.
# eval is necessary to expand ac_cpp.
AC_DEFUN([_AC_PREPROC_IFELSE],
-[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
-AS_IF([_AC_DO_STDERR([$ac_cpp conftest.$ac_ext]) >/dev/null && {
- test -z "$ac_[]_AC_LANG_ABBREV[]_preproc_warn_flag$ac_[]_AC_LANG_ABBREV
[]_werror_flag" ||
- test ! -s conftest.err
- }],
- [$2],
- [_AC_MSG_LOG_CONFTEST
- $3])
-rm -f conftest.err m4_ifval([$1], [conftest.$ac_ext])[]dnl
+[AC_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_try_cpp],
+ [AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_try_cpp], [LINENO],
+ [Try to preprocess conftest.$ac_ext, and return whether this succeeded.])],
+ [$0_BODY])]dnl
+[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])]dnl
+[AS_IF([ac_func_[]_AC_LANG_ABBREV[]_try_cpp "$LINENO"], [$2], [$3])
+m4_ifvaln([$1], [rm -f conftest.$ac_ext])dnl
])# _AC_PREPROC_IFELSE
-
# AC_PREPROC_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
# ---------------------------------------------------------------
# Try to preprocess PROGRAM. Requires that the preprocessor for the
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 5ed52d4..9ef15f5 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -317,11 +317,14 @@ m4_divert_pop[]dnl
# Note: we expand _m4_divert_desired before passing it to m4_divert_require,
# otherwise we would need to use m4_pushdef and m4_popdef instead of
# simply m4_define.
+#
+# Since $2 can be quite large, this is factored for faster execution, giving
+# either m4_require([$1], [$2]) or m4_divert_require(desired, [$1], [$2]).
m4_defun([AS_REQUIRE],
-[m4_define([_m4_divert_desired], [m4_default_quoted([$3], [M4SH-INIT])])dnl
-m4_if(m4_eval(_m4_divert(_m4_divert_dump) <= _m4_divert(_m4_divert_desired)),
1,
- [m4_require([$1], [$2])],
- [m4_divert_require(_m4_divert(_m4_divert_desired), [$1], [$2])])])
+[m4_define([_m4_divert_desired], [m4_default_quoted([$3], [M4SH-INIT])])]dnl
+[m4_if(m4_eval(_m4_divert(_m4_divert_dump) <= _m4_divert(_m4_divert_desired)),
+ 1, [m4_require(],
+ [m4_divert_require(_m4_divert(_m4_divert_desired),]) [$1], [$2])])
# AS_REQUIRE_SHELL_FN(NAME-TO-CHECK, COMMENT, BODY-TO-EXPAND,
@@ -333,12 +336,14 @@ m4_if(m4_eval(_m4_divert(_m4_divert_dump) <= _m4_divert
(_m4_divert_desired)), 1,
# provided (often via AS_FUNCTION_DESCRIBE), it is listed with a
# newline before the function name.
m4_define([AS_REQUIRE_SHELL_FN],
+[m4_provide_if([AS_SHELL_FN_$1], [],
[AS_REQUIRE([AS_SHELL_FN_$1],
-[m4_provide([AS_SHELL_FN_$1])m4_n([$2])$1 ()
+[m4_provide([AS_SHELL_FN_$1])
+m4_n([$2])$1 ()
{
$3
} [#] $1
-], m4_default_quoted([$4], [M4SH-INIT-FN]))])
+], m4_default_quoted([$4], [M4SH-INIT-FN]))])])
# _AS_RUN(TEST, [SHELL])
--
1.6.0.2