150-libtool-mitigate-the-sed_quote_subst-slowdown.patch 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. From 3adadb568fbf15d952bd25a005b6a9afb7e59dc7 Mon Sep 17 00:00:00 2001
  2. From: Pavel Raiskup <[email protected]>
  3. Date: Sun, 4 Oct 2015 21:55:03 +0200
  4. Subject: libtool: mitigate the $sed_quote_subst slowdown
  5. When it is reasonably possible, use shell implementation for
  6. quoting.
  7. References:
  8. http://lists.gnu.org/archive/html/libtool/2015-03/msg00005.html
  9. http://lists.gnu.org/archive/html/libtool/2015-02/msg00000.html
  10. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20006
  11. * gl/build-aux/funclib.sh (func_quote): New function that can be
  12. used as substitution for '$SED $sed_quote_subst' call.
  13. * build-aux/ltmain.in (func_emit_wrapper): Use func_quote instead
  14. of '$SED $sed_quote_subst'.
  15. (func_mode_link): Likewise.
  16. * NEWS: Document.
  17. * bootstrap: Sync with funclib.sh.
  18. (cherry picked from commit 32f0df9835ac15ac17e04be57c368172c3ad1d19)
  19. (skipping NEWS change)
  20. Signed-off-by: Eneas U de Queiroz <[email protected]>
  21. --- a/bootstrap
  22. +++ b/bootstrap
  23. @@ -230,7 +230,7 @@ vc_ignore=
  24. # Source required external libraries:
  25. # Set a version string for this script.
  26. -scriptversion=2015-01-20.17; # UTC
  27. +scriptversion=2015-10-04.22; # UTC
  28. # General shell script boiler plate, and helper functions.
  29. # Written by Gary V. Vaughan, 2004
  30. @@ -1257,6 +1257,57 @@ func_relative_path ()
  31. }
  32. +# func_quote ARG
  33. +# --------------
  34. +# Aesthetically quote one ARG, store the result into $func_quote_result. Note
  35. +# that we keep attention to performance here (so far O(N) complexity as long as
  36. +# func_append is O(1)).
  37. +func_quote ()
  38. +{
  39. + $debug_cmd
  40. +
  41. + func_quote_result=$1
  42. +
  43. + case $func_quote_result in
  44. + *[\\\`\"\$]*)
  45. + case $func_quote_result in
  46. + *'*'*|*'['*)
  47. + func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"`
  48. + return 0
  49. + ;;
  50. + esac
  51. +
  52. + func_quote_old_IFS=$IFS
  53. + for _G_char in '\' '`' '"' '$'
  54. + do
  55. + # STATE($1) PREV($2) SEPARATOR($3)
  56. + set start "" ""
  57. + func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy
  58. + IFS=$_G_char
  59. + for _G_part in $func_quote_result
  60. + do
  61. + case $1 in
  62. + quote)
  63. + func_append func_quote_result "$3$2"
  64. + set quote "$_G_part" "\\$_G_char"
  65. + ;;
  66. + start)
  67. + set first "" ""
  68. + func_quote_result=
  69. + ;;
  70. + first)
  71. + set quote "$_G_part" ""
  72. + ;;
  73. + esac
  74. + done
  75. + IFS=$func_quote_old_IFS
  76. + done
  77. + ;;
  78. + *) ;;
  79. + esac
  80. +}
  81. +
  82. +
  83. # func_quote_for_eval ARG...
  84. # --------------------------
  85. # Aesthetically quote ARGs to be evaled later.
  86. @@ -1273,12 +1324,8 @@ func_quote_for_eval ()
  87. func_quote_for_eval_unquoted_result=
  88. func_quote_for_eval_result=
  89. while test 0 -lt $#; do
  90. - case $1 in
  91. - *[\\\`\"\$]*)
  92. - _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
  93. - *)
  94. - _G_unquoted_arg=$1 ;;
  95. - esac
  96. + func_quote "$1"
  97. + _G_unquoted_arg=$func_quote_result
  98. if test -n "$func_quote_for_eval_unquoted_result"; then
  99. func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
  100. else
  101. --- a/build-aux/ltmain.in
  102. +++ b/build-aux/ltmain.in
  103. @@ -3356,7 +3356,8 @@ else
  104. if test \"\$libtool_execute_magic\" != \"$magic\"; then
  105. file=\"\$0\""
  106. - qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"`
  107. + func_quote "$ECHO"
  108. + qECHO=$func_quote_result
  109. $ECHO "\
  110. # A function that is used when there is no print builtin or printf.
  111. @@ -8618,8 +8619,8 @@ EOF
  112. relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command"
  113. fi
  114. done
  115. - relink_command="(cd `pwd`; $relink_command)"
  116. - relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
  117. + func_quote "(cd `pwd`; $relink_command)"
  118. + relink_command=$func_quote_result
  119. fi
  120. # Only actually do things if not in dry run mode.
  121. @@ -8865,7 +8866,8 @@ EOF
  122. done
  123. # Quote the link command for shipping.
  124. relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
  125. - relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"`
  126. + func_quote "$relink_command"
  127. + relink_command=$func_quote_result
  128. if test yes = "$hardcode_automatic"; then
  129. relink_command=
  130. fi
  131. --- a/build-aux/funclib.sh
  132. +++ b/build-aux/funclib.sh
  133. @@ -1,5 +1,5 @@
  134. # Set a version string for this script.
  135. -scriptversion=2015-01-20.17; # UTC
  136. +scriptversion=2015-10-04.22; # UTC
  137. # General shell script boiler plate, and helper functions.
  138. # Written by Gary V. Vaughan, 2004
  139. @@ -1026,6 +1026,57 @@ func_relative_path ()
  140. }
  141. +# func_quote ARG
  142. +# --------------
  143. +# Aesthetically quote one ARG, store the result into $func_quote_result. Note
  144. +# that we keep attention to performance here (so far O(N) complexity as long as
  145. +# func_append is O(1)).
  146. +func_quote ()
  147. +{
  148. + $debug_cmd
  149. +
  150. + func_quote_result=$1
  151. +
  152. + case $func_quote_result in
  153. + *[\\\`\"\$]*)
  154. + case $func_quote_result in
  155. + *[\[\*\?]*)
  156. + func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"`
  157. + return 0
  158. + ;;
  159. + esac
  160. +
  161. + func_quote_old_IFS=$IFS
  162. + for _G_char in '\' '`' '"' '$'
  163. + do
  164. + # STATE($1) PREV($2) SEPARATOR($3)
  165. + set start "" ""
  166. + func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy
  167. + IFS=$_G_char
  168. + for _G_part in $func_quote_result
  169. + do
  170. + case $1 in
  171. + quote)
  172. + func_append func_quote_result "$3$2"
  173. + set quote "$_G_part" "\\$_G_char"
  174. + ;;
  175. + start)
  176. + set first "" ""
  177. + func_quote_result=
  178. + ;;
  179. + first)
  180. + set quote "$_G_part" ""
  181. + ;;
  182. + esac
  183. + done
  184. + IFS=$func_quote_old_IFS
  185. + done
  186. + ;;
  187. + *) ;;
  188. + esac
  189. +}
  190. +
  191. +
  192. # func_quote_for_eval ARG...
  193. # --------------------------
  194. # Aesthetically quote ARGs to be evaled later.
  195. @@ -1042,12 +1093,8 @@ func_quote_for_eval ()
  196. func_quote_for_eval_unquoted_result=
  197. func_quote_for_eval_result=
  198. while test 0 -lt $#; do
  199. - case $1 in
  200. - *[\\\`\"\$]*)
  201. - _G_unquoted_arg=`printf '%s\n' "$1" |$SED "$sed_quote_subst"` ;;
  202. - *)
  203. - _G_unquoted_arg=$1 ;;
  204. - esac
  205. + func_quote "$1"
  206. + _G_unquoted_arg=$func_quote_result
  207. if test -n "$func_quote_for_eval_unquoted_result"; then
  208. func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg"
  209. else