Subject: Re: Get rid of excessive sed forks

From: Harald Hoyer <[email-masked]>
Date: Thu, 05 Mar 2015 09:52:05 +0100

On 05.03.2015 09:29, Harald Hoyer wrote:
> See
> https://harald.hoyer.xyz/2015/03/05/libtool-getting-rid-of-180000-sed-forks/
> 
> Patch attached.
> 

Corrected patch attached
--- libtool.orig	2015-03-04 15:44:39.632703654 +0100
+++ libtool.fixed	2015-03-05 09:51:17.321333343 +0100
@@ -1607,7 +1607,15 @@
     while test 0 -lt $#; do
       case $1 in
         *[\\\`\"\$]*)
-	  _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
+          if test set = "${BASH_VERSION+set}"; then
+            _G_unquoted_arg=${1//\\/\\\\}
+            _G_unquoted_arg=${_G_unquoted_arg//\"/\\\"}
+            _G_unquoted_arg=${_G_unquoted_arg//\$/\\\$}
+            _G_unquoted_arg=${_G_unquoted_arg//\`/\\\`}
+          else
+              _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"`
+          fi
+          ;;
         *)
           _G_unquoted_arg=$1 ;;
       esac
@@ -5756,7 +5764,11 @@
   if test \"\$libtool_execute_magic\" != \"$magic\"; then
     file=\"\$0\""
 
-    qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
+    if test set = "${BASH_VERSION+set}"; then
+      qECHO=$(_G=$($ECHO "$ECHO");_G=${_G//\\/\\\\};_G=${_G//\"/\\\"};_G=${_G//\$/\\\$};_G=${_G//\`/\\\`};printf '%s\n' "$_G")
+    else
+      qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
+    fi
     $ECHO "\
 
 # A function that is used when there is no print builtin or printf.