summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2016-01-31 21:22:10 +0000
committerdteske <dteske@FreeBSD.org>2016-01-31 21:22:10 +0000
commit089e1927c5f216d8771aed2b3c7cd3fb97a84663 (patch)
tree900203a02f87d4b43974d2bf1ff37a557ec52745 /usr.sbin/bsdconfig
parent37617f7cb005082f23a6727fb7fdf8740ea668d9 (diff)
downloadFreeBSD-src-089e1927c5f216d8771aed2b3c7cd3fb97a84663.zip
FreeBSD-src-089e1927c5f216d8771aed2b3c7cd3fb97a84663.tar.gz
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.
Diffstat (limited to 'usr.sbin/bsdconfig')
-rw-r--r--usr.sbin/bsdconfig/share/strings.subr10
1 files changed, 9 insertions, 1 deletions
diff --git a/usr.sbin/bsdconfig/share/strings.subr b/usr.sbin/bsdconfig/share/strings.subr
index e0cd7e0..aafa891 100644
--- a/usr.sbin/bsdconfig/share/strings.subr
+++ b/usr.sbin/bsdconfig/share/strings.subr
@@ -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
OpenPOWER on IntegriCloud