autoconf-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 05/12] use a shell function for AC_CHECK_FUNC


From: Eric Blake
Subject: Re: [PATCH 05/12] use a shell function for AC_CHECK_FUNC
Date: Fri, 24 Oct 2008 21:31:05 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Paolo Bonzini <bonzini <at> gnu.org> writes:

> 
> Here we go with the most used AC_CHECK_* functions.  These further
> reduce by another 10%.  Autoconf becomes faster by 20-30% too,
> because several complex macros are expanded only once as part of
> the shell function.
> 
> 2008-10-12  Paolo Bonzini  <bonzini <at> gnu.org>
> 
>       * lib/autoconf/general.m4 (AC_CHECK_FUNC): Use a shell function.

ChangeLog was a bit wrong.  In addition to that, I'm squashing in the 
following.  Your double use of AS_VAR_PUSHDEF resulted in two extra forks per 
AC_CHECK_FUNC compared to pre-patch (if the variable is an indirect, as is the 
case with ac_cv_func_$2 in the function body, AS_VAR_PUSHDEF results in 
`echo|tr`, which is a double fork for command substitution and a pipe).  By 
adding a third parameter, and recognizing that $3 is always indirect (never 
literal) and already sufficient to not need further translation, we can arrange 
it so only the call site needs to fork, and only if the function name is an 
indirect to begin with.  And while reducing the number of forks, I spotted a 
quick-and-dirty way to reduce the number of cat(1) calls.

diff --git a/ChangeLog b/ChangeLog
index b26d7ca..61b5f33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-24  Paolo Bonzini  <address@hidden>
+       and Eric Blake  <address@hidden>
+
+       Use a shell function for AC_CHECK_FUNC.
+       * lib/autoconf/functions.m4 (_AC_CHECK_FUNC_BODY): New macro.
+       (AC_CHECK_FUNC): Use a shell function.
+       * lib/autoconf/c.m4 (AC_LANG_SOURCE(C)): Reduce number of forks.
+
 2008-10-24  Eric Blake  <address@hidden>
 
        Work around fact that gnulib-tool doesn't use m4_copy.
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index f3b3e5f..90a091c 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -189,8 +189,7 @@ m4_define([_AC_LANG_PREFIX(Objective C)], [OBJC])
 m4_define([AC_LANG_SOURCE(C)],
 [/* confdefs.h.  */
 _ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
+cat confdefs.h - <<_ACEOF >>conftest.$ac_ext
 /* end confdefs.h.  */
 $1])
 
diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4
index 8b02596..0bc9299 100644
--- a/lib/autoconf/functions.m4
+++ b/lib/autoconf/functions.m4
@@ -61,27 +61,34 @@
 ## 1. Generic tests for functions.  ##
 ## -------------------------------- ##
 
+# _AC_CHECK_FUNC_BODY
+# -------------------
+# Shell function body for AC_CHECK_FUNC.
+m4_define([_AC_CHECK_FUNC_BODY],
+[  AS_LINENO_PUSH([$[]1])
+  AC_CACHE_CHECK([for $[]2], [$[]3],
+  [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY($[]2)],
+                 [AS_VAR_SET([$[]3], [yes])],
+                 [AS_VAR_SET([$[]3], [no])])])
+  AS_LINENO_POP
+])# _AC_CHECK_FUNC_BODY
+
 
 # AC_CHECK_FUNC(FUNCTION, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
 # -----------------------------------------------------------------
+# Check whether FUNCTION links in the current language.  Set the cache
+# variable ac_cv_func_FUNCTION accordingly, then execute
+# ACTION-IF-FOUND or ACTION-IF-NOT-FOUND.
 AC_DEFUN([AC_CHECK_FUNC],
 [AC_REQUIRE_SHELL_FN([ac_func_]_AC_LANG_ABBREV[_check_func],
-  [AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_check_func], [LINENO FUNC],
-    [Tests whether FUNC exists, setting a cache variable accordingly])], [
-  AS_LINENO_PUSH([$[]1])
-  AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$[]2])dnl
-  AC_CACHE_CHECK([for $[]2], [ac_var],
-  [AC_LINK_IFELSE([AC_LANG_FUNC_LINK_TRY([$][2])],
-                 [AS_VAR_SET([ac_var], [yes])],
-                 [AS_VAR_SET([ac_var], [no])])])
-  AS_VAR_POPDEF([ac_var])dnl
-  AS_LINENO_POP
-])dnl
-ac_func_[]_AC_LANG_ABBREV[]_check_func "$LINENO" "$1"
-AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])dnl
+  [AS_FUNCTION_DESCRIBE([ac_func_]_AC_LANG_ABBREV[_check_func],
+    [LINENO FUNC VAR],
+    [Tests whether FUNC exists, setting the cache variable VAR accordingly])],
+  [_$0_BODY])]dnl
+[AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])]dnl
+[ac_func_[]_AC_LANG_ABBREV[]_check_func "$LINENO" "$1" "ac_var"
 AS_VAR_IF([ac_var], [yes], [$2], [$3])
-AS_VAR_POPDEF([ac_var])dnl
-])# AC_CHECK_FUNC
+AS_VAR_POPDEF([ac_var])])# AC_CHECK_FUNC
 
 
 # _AH_CHECK_FUNCS(FUNCTION...)







reply via email to

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