found one real slowdown, wc -c <<< $VAR is way slower than ${#VAR} branch one

This commit is contained in:
inxi-svn 2014-03-14 01:12:30 +00:00
parent fc5702f0ec
commit 783c9b04c2

29
inxi
View file

@ -3,7 +3,7 @@
#### Script Name: inxi #### Script Name: inxi
#### Version: 2.0.0 #### Version: 2.0.0
#### Date: 2014-03-12 #### Date: 2014-03-12
#### Patch Number: 01-b1 #### Patch Number: 02-b1
######################################################################## ########################################################################
#### SPECIAL THANKS #### SPECIAL THANKS
######################################################################## ########################################################################
@ -166,6 +166,7 @@
######################################################################## ########################################################################
#### Valuable Resources #### Valuable Resources
#### CPU flags: http://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean #### CPU flags: http://unix.stackexchange.com/questions/43539/what-do-the-flags-in-proc-cpuinfo-mean
#### Advanced Bash: http://wiki.bash-hackers.org/syntax/pe
#### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html #### gawk arrays: http://www.math.utah.edu/docs/info/gawk_12.html
#### raid mdstat: http://www-01.ibm.com/support/docview.wss?uid=isg3T1011259 #### raid mdstat: http://www-01.ibm.com/support/docview.wss?uid=isg3T1011259
#### http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array #### http://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array
@ -2638,7 +2639,8 @@ print_lines_basic()
b_indent_x='false' b_indent_x='false'
;; ;;
1) indent_full=$indent_main 1) indent_full=$indent_main
temp_count=$( wc -c <<< $2 ) # temp_count=$( wc -c <<< $2 )
temp_count=${#2}
if [[ $temp_count -lt $indent_full ]];then if [[ $temp_count -lt $indent_full ]];then
indent_working=$indent_full indent_working=$indent_full
else else
@ -2649,7 +2651,7 @@ print_lines_basic()
# first left pad 2 and 3, then right pad them # first left pad 2 and 3, then right pad them
2) indent_full=$(( $indent_main + 6 )) 2) indent_full=$(( $indent_main + 6 ))
indent_inner=3 indent_inner=3
temp_count=$( wc -c <<< $2 ) temp_count=${#2}
if [[ $temp_count -lt $indent_inner ]];then if [[ $temp_count -lt $indent_inner ]];then
indent_working=$indent_inner indent_working=$indent_inner
else else
@ -2660,7 +2662,7 @@ print_lines_basic()
;; ;;
3) indent_full=$(( $indent_main + 8 )) 3) indent_full=$(( $indent_main + 8 ))
indent_inner=3 indent_inner=3
temp_count=$( wc -c <<< $2 ) temp_count=${#2}
if [[ $temp_count -lt $indent_inner ]];then if [[ $temp_count -lt $indent_inner ]];then
indent_working=$indent_inner indent_working=$indent_inner
else else
@ -2671,7 +2673,7 @@ print_lines_basic()
;; ;;
# for long options # for long options
4) indent_full=$(( $indent_main + 8 )) 4) indent_full=$(( $indent_main + 8 ))
temp_count=$( wc -c <<< $2 ) temp_count=${#2}
if [[ $temp_count -lt $indent_full ]];then if [[ $temp_count -lt $indent_full ]];then
indent_working=$indent_full indent_working=$indent_full
else else
@ -2689,13 +2691,16 @@ print_lines_basic()
line_count=$(( $line_width - $indent_full )) line_count=$(( $line_width - $indent_full ))
# bash loop is so slow, only run this if required # bash loop is so slow, only run this if required
if [[ $( wc -c <<< $3 ) -gt $line_count ]];then # temp_count=$( wc -c <<< $3 )
temp_count=${#3}
if [[ $temp_count -gt $line_count ]];then
for word in $3 for word in $3
do do
temp_string="$print_string$spacer$word" temp_string="$print_string$spacer$word"
spacer=' ' spacer=' '
# note: wc -c here will return +1 actual string length # note: wc -c here will return +1 actual string length
temp_count=$( wc -c <<< $temp_string ) #temp_count=$( wc -c <<< $temp_string )
temp_count=${#temp_string}
if [[ $temp_count -lt $line_count ]];then if [[ $temp_count -lt $line_count ]];then
print_string=$temp_string # lose any white space start/end print_string=$temp_string # lose any white space start/end
# echo -n $(( $line_width - $indent_full )) # echo -n $(( $line_width - $indent_full ))
@ -8730,7 +8735,8 @@ calculate_line_length()
local string="$1" local string="$1"
# ansi:  irc: \x0312 # ansi:  irc: \x0312
string=$( sed -e "s/\x1b\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g" -e "s/\\\x0[0-9]\{1,3\}//g" <<< $string ) string=$( sed -e "s/\x1b\[[0-9]\{1,2\}\(;[0-9]\{1,2\}\)\{0,2\}m//g" -e "s/\\\x0[0-9]\{1,3\}//g" <<< $string )
count=$( wc -c <<< $string ) # count=$( wc -c <<< $string )
count=${#string}
echo $count echo $count
} }
@ -9287,7 +9293,7 @@ print_cpu_flags_full()
eval $LOGFS eval $LOGFS
# note: sort only sorts lines, not words in a string, so convert to lines # note: sort only sorts lines, not words in a string, so convert to lines
local cpu_flags_full="$( echo $1 | tr " " "\n" | sort )" local cpu_flags_full="$( echo $1 | tr " " "\n" | sort )"
local a_cpu_flags='' line_starter='' local a_cpu_flags='' line_starter='' temp_count=''
local i=0 counter=0 max_length=85 max_length_minus=15 flag='' flag_data='' local i=0 counter=0 max_length=85 max_length_minus=15 flag='' flag_data=''
local line_length_max='' flag_feature='Flags' local line_length_max='' flag_feature='Flags'
@ -9305,8 +9311,9 @@ print_cpu_flags_full()
else else
line_length_max=$max_length line_length_max=$max_length
fi fi
# temp_count=$( wc -c <<< ${a_cpu_flags[$counter]} )
if [[ $( wc -c <<< ${a_cpu_flags[$counter]} ) -gt $line_length_max ]];then temp_count=${#a_cpu_flags[$counter]}
if [[ $temp_count -gt $line_length_max ]];then
(( counter++ )) (( counter++ ))
fi fi
done done