1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-23 11:18:54 +00:00

Optimize f_expand_number(), improving performance.

MFC After:	3 days
This commit is contained in:
Devin Teske 2014-01-19 21:02:24 +00:00
parent 1a75471bbb
commit ae978c3682
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=260894

View File

@ -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)