diff options
author | dteske <dteske@FreeBSD.org> | 2014-01-19 21:02:24 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2014-01-19 21:02:24 +0000 |
commit | fa3ef88a5b1ffa91d48bdb5080d9000bbb0a29f7 (patch) | |
tree | 946e7550936e7b0c19298bf41e424849860aea9b | |
parent | 7bfb83bbfe15249c9e07306d9a368cd09ca2fe68 (diff) | |
download | FreeBSD-src-fa3ef88a5b1ffa91d48bdb5080d9000bbb0a29f7.zip FreeBSD-src-fa3ef88a5b1ffa91d48bdb5080d9000bbb0a29f7.tar.gz |
Optimize f_expand_number(), improving performance.
MFC After: 3 days
-rw-r--r-- | usr.sbin/bsdconfig/share/strings.subr | 30 |
1 files changed, 6 insertions, 24 deletions
diff --git a/usr.sbin/bsdconfig/share/strings.subr b/usr.sbin/bsdconfig/share/strings.subr index 9b0014f..c41dc37 100644 --- a/usr.sbin/bsdconfig/share/strings.subr +++ b/usr.sbin/bsdconfig/share/strings.subr @@ -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) |