autoconf-patches
[Top][All Lists]
Advanced

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

faster AS_ECHO on Solaris


From: Eric Blake
Subject: faster AS_ECHO on Solaris
Date: Mon, 10 Nov 2008 16:10:59 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Based on the recent libtool threads, I'm installing this.  I've tested that on 
Solaris 8, with a highly restricted PATH, that this allows fewer forks when ksh 
is the only winning shell available; meanwhile, when only /bin/sh is available 
(and thus no print builtin), the existing forking fallbacks are still 
selected.  I also made sure that it didn't add a 2-fork penalty to shells where 
we know print(1) does not exist.

From: Eric Blake <address@hidden>
Date: Mon, 10 Nov 2008 08:28:48 -0700
Subject: [PATCH] Try 'print -r --' as a non-forking variant of 'printf %s\\n'.

* lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Cater to Solaris ksh.
* doc/autoconf.texi (Limitations of Builtins) <printf>: Document
the print workaround.
Idea by Paolo Bonzini.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |    8 ++++++++
 doc/autoconf.texi   |    6 ++++++
 lib/m4sugar/m4sh.m4 |   10 ++++++++--
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5ddd2f7..6dd25c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2008-11-10  Eric Blake  <address@hidden>
 
+       Try 'print -r --' as a non-forking variant of 'printf %s\\n'.
+       * lib/m4sugar/m4sh.m4 (_AS_ECHO_PREPARE): Cater to Solaris ksh.
+       * doc/autoconf.texi (Limitations of Builtins) <printf>: Document
+       the print workaround.
+       Idea by Paolo Bonzini.
+
+2008-11-10  Eric Blake  <address@hidden>
+
        Provide a section on all tools allowed in GNU Coding Standards.
        * doc/autoconf.texi (Limitations of Builtins) <read>: Sort.
        <wait>: Add section.
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index f59be60..86bed7f 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -15291,6 +15291,12 @@ Limitations of Builtins
 @command{/bin/sh} the command @samp{printf %010000x 123} normally dumps
 core.
 
+Since @command{printf} is not always a shell builtin, there is a
+potential speed penalty for using @code{printf %s\\n} as a replacement
+for an @command{echo} that does not interpret @samp{\} or leading
address@hidden With Solaris @command{ksh}, it is possible to use @code{print
+-r --} for this role instead.
+
 
 @item @command{pwd}
 @c ----------------
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index a506ef0..e0b7c55 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -875,7 +875,7 @@ m4_defun_init([AS_ECHO_N],
 # _AS_ECHO_PREPARE
 # -----------------
 # Arrange for $as_echo 'FOO' to echo FOO without escape-interpretation;
-# and similarly for $as_echo_foo, which omits the trailing newline.
+# and similarly for $as_echo_n, which omits the trailing newline.
 # 'FOO' is an optional single argument; a missing FOO is treated as empty.
 m4_defun([_AS_ECHO_PREPARE],
 [[as_nl='
@@ -885,7 +885,13 @@ export as_nl
 
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
 as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
 as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
-if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
+# Prefer a ksh shell builtin over an external printf program on Solaris,
+# but without wasting forks for bash or zsh.
+if test -z "$BASH_VERSION$ZSH_VERSION" \
+    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
+  as_echo='print -r --'
+  as_echo_n='print -rn --'
+elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
   as_echo='printf %s\n'
   as_echo_n='printf %s'
 else
-- 
1.6.0.2








reply via email to

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