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:
parent
57ef9b750b
commit
fcb16c1036
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user