Optimize f_sprintf() for bash

bash lacks the ksh93 optimization that makes sub-shells fast if they do
not alter io. bash 3.1-alpha1 introduced printf -v var_to_set which is not
as fast but is still significantly faster than var_to_set=$( printf ) when
using any version of bash. If we find our interpreter to somehow be bash
by invocation or inclusion, use the feature that provides fastest results.
This commit is contained in:
Devin Teske 2016-01-31 21:22:10 +00:00
parent 57ef9b750b
commit fcb16c1036
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=295101

View File

@ -138,7 +138,15 @@ f_sprintf()
{
local __var_to_set="$1"
shift 1 # var_to_set
eval "$__var_to_set"=\$\( printf -- \"\$@\" \)
case "$BASH_VERSION" in
3.1*|4.*)
local __tmp
printf -v __tmp "$@"
eval "$__var_to_set"=\"\${__tmp%\$NL}\"
;;
*) eval "$__var_to_set"=\$\( printf -- \"\$@\" \)
esac
}
# f_vsnprintf $var_to_set $size $format $format_args