Author: dteske
Date: Sun Jan 31 21:22:10 2016
New Revision: 295101
URL: https://svnweb.freebsd.org/changeset/base/295101

Log:
  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.

Modified:
  head/usr.sbin/bsdconfig/share/strings.subr

Modified: head/usr.sbin/bsdconfig/share/strings.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/strings.subr  Sun Jan 31 21:14:31 2016        
(r295100)
+++ head/usr.sbin/bsdconfig/share/strings.subr  Sun Jan 31 21:22:10 2016        
(r295101)
@@ -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
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to