Date: Sun, 19 Jan 2014 21:02:24 +0000 (UTC) From: Devin Teske <dteske@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260894 - head/usr.sbin/bsdconfig/share Message-ID: <201401192102.s0JL2Opt000133@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dteske Date: Sun Jan 19 21:02:24 2014 New Revision: 260894 URL: http://svnweb.freebsd.org/changeset/base/260894 Log: Optimize f_expand_number(), improving performance. MFC After: 3 days 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 19 20:32:20 2014 (r260893) +++ head/usr.sbin/bsdconfig/share/strings.subr Sun Jan 19 21:02:24 2014 (r260894) @@ -372,14 +372,13 @@ f_expand_number() local __cp __num __bshift __maxinput # Remove any leading non-digits - while :; do - __cp="$__string" - __string="${__cp#[!0-9]}" - [ "$__string" = "$__cp" ] && break - done + __string="${__string#${__string%%[0-9]*}}" + + # Store the numbers (no trailing suffix) + __num="${__string%%[!0-9]*}" # Produce `-1' if string didn't contain any digits - if [ ! "$__string" ]; then + if [ ! "$__num" ]; then if [ "$__var_to_set" ]; then setvar "$__var_to_set" -1 else @@ -388,25 +387,8 @@ f_expand_number() return 1 # 1 = "Given $string contains no digits" fi - # Store the numbers - __num="${__string%%[!0-9]*}" - - # Shortcut - if [ $__num -eq 0 ]; then - if [ "$__var_to_set" ]; then - setvar "$__var_to_set" 0 - else - echo 0 - fi - return $SUCCESS - fi - # Remove all the leading numbers from the string to get at the prefix - while :; do - __cp="$__string" - __string="${__cp#[0-9]}" - [ "$__string" = "$__cp" ] && break - done + __string="${__string#"$__num"}" # # Test for invalid prefix (and determine bitshift length)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201401192102.s0JL2Opt000133>