autoconf-patches
[Top][All Lists]
Advanced

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

(was: Portability of shell parameter expansions (${word%pattern} and) fr


From: Ralf Wildenhues
Subject: (was: Portability of shell parameter expansions (${word%pattern} and) friends)?
Date: Thu, 8 Nov 2007 22:40:41 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

[ moving from autoconf@ ]

* Ralf Wildenhues wrote on Tue, Nov 06, 2007 at 06:22:37PM CET:
> Same issue.  You should be able to factorize likewise with shell
> functions, similar to Libtool's approach:
> 
> # ac_func_arith
[...]
> The above could help save a few forks in Autotest (plus one per test)
> and some in _AC_FEATURE_CHECK_LENGTH, _AC_COMPUTE_INT_COMPILE (when
> Autoconf starts to use shell functions).

Let's start with Autotest.  OK?

This saves almost 10% execution time on the `Empty test' on Linux.  ;-)
(but I still owe an apology to Paolo for not finishing his patch first.)

Cheers,
Ralf

    Avoid expr for arithmetic evaluation if the shell accepts $((...)).
    
    * lib/autotest/general.m4 (AT_INIT) <at_func_arith>: New
    function, to parametrize arithmetic with expr vs. the shell.
    Use it where possible.
    Suggestion by Benoit Sigoure.
    
    Signed-off-by: Ralf Wildenhues <address@hidden>

diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 29834f1..4d92e6d 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -337,6 +337,24 @@ at_func_create_debugging_script ()
   chmod +x $at_group_dir/run
 }
 
+# at_func_arith
+# -------------
+# Arithmetic evaluation, avoids expr if the shell is sane.
+#
+# subshell and eval are needed to keep Solaris sh from bailing out:
+if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then
+  [#] With "address@hidden", bash does not split positional parameters:
+  eval 'at_func_arith ()
+  {
+    at_func_arith_result=$(( $[*] ))
+  }'
+else
+  at_func_arith ()
+  {
+    at_func_arith_result=`expr "address@hidden"`
+  }
+fi
+
 ## ---------------------- ##
 ## End of shell functions ##
 ## ---------------------- ##
@@ -905,7 +923,8 @@ do
 _ATEOF
     AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
   fi
-  at_group_count=`expr 1 + $at_group_count`
+  at_func_arith 1 + $at_group_count
+  at_group_count=$at_func_arith_result
   $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
   AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
   case $at_xfail:$at_status in
@@ -982,11 +1001,16 @@ at_stop_time=`date +%s 2>/dev/null`
 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
 case $at_start_time,$at_stop_time in
   [[0-9]*,[0-9]*])
-    at_duration_s=`expr $at_stop_time - $at_start_time`
-    at_duration_m=`expr $at_duration_s / 60`
-    at_duration_h=`expr $at_duration_m / 60`
-    at_duration_s=`expr $at_duration_s % 60`
-    at_duration_m=`expr $at_duration_m % 60`
+    at_func_arith $at_stop_time - $at_start_time
+    at_duration_s=$at_func_arith_result
+    at_func_arith $at_duration_s / 60
+    at_duration_m=$at_func_arith_result
+    at_func_arith $at_duration_m / 60
+    at_duration_h=$at_func_arith_result
+    at_func_arith $at_duration_s % 60
+    at_duration_s=$at_func_arith_result
+    at_func_arith $at_duration_m % 60
+    at_duration_m=$at_func_arith_result
     at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
     AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
     ;;
@@ -998,9 +1022,12 @@ set X $at_fail_list; shift; address@hidden:@]
 set X $at_xpass_list; shift; address@hidden:@]
 set X $at_xfail_list; shift; address@hidden:@]
 
-at_run_count=`expr $at_group_count - $at_skip_count`
-at_unexpected_count=`expr $at_xpass_count + $at_fail_count`
-at_total_fail_count=`expr $at_xfail_count + $at_fail_count`
+at_func_arith $at_group_count - $at_skip_count
+at_run_count=$at_func_arith_result
+at_func_arith $at_xpass_count + $at_fail_count
+at_unexpected_count=$at_func_arith_result
+at_func_arith $at_xfail_count + $at_fail_count
+at_total_fail_count=$at_func_arith_result
 
 echo
 AS_BOX([Test results.])




reply via email to

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