libtool-patches
[Top][All Lists]
Advanced

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

slight optimization: less subshells


From: Ralf Wildenhues
Subject: slight optimization: less subshells
Date: Mon, 31 Jan 2005 16:55:33 +0100
User-agent: Mutt/1.4.1i

http://lists.gnu.org/archive/html/autoconf-patches/2005-01/msg00072.html
and following discussion showed that changing  `( cmd ) 2>/dev/null' to
`{ cmd; } 2>/dev/null' yields no benefit in most cases.  However, if cmd
is a builtin (or has good chances of being a builtin), this is different
and measurable even on newer systems, for example cygwin.

It is suspected that some older shells might not get the redirection
right and might in fact output something on stderr, but no such shell
has been named (and I haven't found one).

With all of this is mind: OK to apply this patch, which changes these
patterns where cmd has a good chance of being builtin, then (HEAD and
branch-2-0)?

Regards,
Ralf

        * config/ltmain.m4sh, m4/libtool.m4: Change `( cmd ) 2>/dev/null' to
        `{ cmd; } 2>/dev/null', when cmd has no side effects and might be a
        builtin.  Note that it is unspecified whether cmd will run within a
        subshell (e.g. Bourne shells) or within the current shell (most modern
        shells).

Index: config/ltmain.m4sh
===================================================================
RCS file: /cvsroot/libtool/libtool/config/ltmain.m4sh,v
retrieving revision 1.47
diff -u -r1.47 ltmain.m4sh
--- config/ltmain.m4sh  26 Jan 2005 17:38:51 -0000      1.47
+++ config/ltmain.m4sh  28 Jan 2005 12:29:37 -0000
@@ -88,7 +88,7 @@
 elif test "X$1" = X--fallback-echo; then
   # Avoid inline document here, it may be left over
   :
-elif test "X`($ECHO '\t') 2>/dev/null`" = 'X\t'; then
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t'; then
   # Yippee, $ECHO works!
   :
 else
@@ -6092,7 +6092,7 @@
     if test \"X\$1\" = X--no-reexec; then
       # Discard the --no-reexec flag, and continue.
       shift
-    elif test \"X\`(\$ECHO '\t') 2>/dev/null\`\" = 'X\t'; then
+    elif test \"X\`{ \$ECHO '\t'; } 2>/dev/null\`\" = 'X\t'; then
       # Yippee, \$ECHO works!
       :
     else
@@ -6564,8 +6564,8 @@
       fi
 
       # Don't error if the file doesn't exist and rm -f was used.
-      if (test -L "$file") >/dev/null 2>&1 ||
-        (test -h "$file") >/dev/null 2>&1 ||
+      if { test -L "$file"; } >/dev/null 2>&1 ||
+        { test -h "$file"; } >/dev/null 2>&1 ||
         test -f "$file"; then
        :
       elif test -d "$file"; then
Index: m4/libtool.m4
===================================================================
RCS file: /cvsroot/libtool/libtool/m4/libtool.m4,v
retrieving revision 1.159
diff -u -r1.159 libtool.m4
--- m4/libtool.m4       26 Jan 2005 17:38:51 -0000      1.159
+++ m4/libtool.m4       28 Jan 2005 12:29:37 -0000
@@ -728,7 +728,7 @@
 elif test "X[$]1" = X--fallback-echo; then
   # Avoid inline document here, it may be left over
   :
-elif test "X`($ECHO '\t') 2>/dev/null`" = 'X\t' ; then
+elif test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' ; then
   # Yippee, $ECHO works!
   :
 else
@@ -754,17 +754,16 @@
     # find a string as large as possible, as long as the shell can cope with it
     for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q 
"[$]0"' 'echo test'; do
       # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
-      if (echo_test_string="`eval $cmd`") 2>/dev/null &&
-         echo_test_string="`eval $cmd`" &&
-         (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null
+      if { echo_test_string="`eval $cmd`"; } 2>/dev/null &&
+        { test "X$echo_test_string" = "X$echo_test_string"; } 2>/dev/null
       then
         break
       fi
     done
   fi
 
-  if test "X`($ECHO '\t') 2>/dev/null`" = 'X\t' &&
-     echo_testing_string=`($ECHO "$echo_test_string") 2>/dev/null` &&
+  if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+     echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
      test "X$echo_testing_string" = "X$echo_test_string"; then
     :
   else
@@ -789,12 +788,12 @@
 
     if test "X$ECHO" = Xecho; then
       # We didn't find a better echo, so look for alternatives.
-      if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
-         echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
+      if test "X`{ print -r '\t'; } 2>/dev/null`" = 'X\t' &&
+         echo_testing_string=`{ print -r "$echo_test_string"; } 2>/dev/null` &&
          test "X$echo_testing_string" = "X$echo_test_string"; then
         # This shell has a builtin print -r that does the trick.
         ECHO='print -r'
-      elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
+      elif { test -f /bin/ksh || test -f /bin/ksh$ac_exeext; } &&
           test "X$CONFIG_SHELL" != X/bin/ksh; then
         # If we have ksh, try running configure again with it.
         ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
@@ -805,23 +804,23 @@
       else
         # Try using printf.
         ECHO='printf %s\n'
-        if test "X`($ECHO '\t') 2>/dev/null`" = 'X\t' &&
-          echo_testing_string=`($ECHO "$echo_test_string") 2>/dev/null` &&
+        if test "X`{ $ECHO '\t'; } 2>/dev/null`" = 'X\t' &&
+          echo_testing_string=`{ $ECHO "$echo_test_string"; } 2>/dev/null` &&
           test "X$echo_testing_string" = "X$echo_test_string"; then
          # Cool, printf works
          :
         elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" 
--fallback-echo '\t') 2>/dev/null` &&
             test "X$echo_testing_string" = 'X\t' &&
             echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" 
--fallback-echo "$echo_test_string") 2>/dev/null` &&
             test "X$echo_testing_string" = "X$echo_test_string"; then
          CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
          export CONFIG_SHELL
          SHELL="$CONFIG_SHELL"
          export SHELL
          ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
         elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 
2>/dev/null` &&
             test "X$echo_testing_string" = 'X\t' &&
             echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo 
"$echo_test_string") 2>/dev/null` &&
             test "X$echo_testing_string" = "X$echo_test_string"; then
          ECHO="$CONFIG_SHELL [$]0 --fallback-echo"
         else
@@ -829,7 +828,7 @@
          prev=:
 
          for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q 
"[$]0"' 'sed 50q "[$]0"'; do
-           if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null
+           if { test "X$echo_test_string" = "X`eval $cmd`"; } 2>/dev/null
            then
              break
            fi
@@ -1191,8 +1190,8 @@
     # If test is not a shell built-in, we'll probably end up computing a
     # maximum length that is only half of the actual maximum length, but
     # we can't tell.
-    while (test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 
2>/dev/null` \
-              = "XX$teststring$teststring") >/dev/null 2>&1 &&
+    while { test "X"`$SHELL [$]0 --fallback-echo "X$teststring$teststring" 
2>/dev/null` \
+              = "XX$teststring$teststring"; } >/dev/null 2>&1 &&
            test $i != 17 # 1/2 MB should be enough
     do
       i=`expr $i + 1`




reply via email to

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