aristocratos / bashtop

Linux/OSX/FreeBSD resource monitor
Apache License 2.0
10.79k stars 552 forks source link

[IMPROVMENT] There's no need to use Associative Arrays #218

Closed F-Hauri closed 2 years ago

F-Hauri commented 2 years ago

Describe the bug

Re-reading my code about braille graphics, I realize:

There's no need to use Associative Arrays

To Reproduce

Have a look at lines 240 to 253:

  declare -A graph_symbol_up='(
        [0_0]=⠀ [0_1]=⢀ [0_2]=⢠ [0_3]=⢰ [0_4]=⢸
        [1_0]=⡀ [1_1]=⣀ [1_2]=⣠ [1_3]=⣰ [1_4]=⣸

could be replaced by

  declare -a graph_symbol_up='(
        [00]=⠀ [01]=⢀ [02]=⢠ [03]=⢰ [04]=⢸
        [10]=⡀ [11]=⣀ [12]=⣠ [13]=⣰ [14]=⣸

Then when used, like at line 1673-1680:

        if [[ -z $add ]] && ((x==0)); then
            print -v graph_even[y] -t "${symbols[${prev_value}${cur_value}]}"
            print -v graph_array[y] -t "${symbols[${prev_value}]}"
        elif [[ -z $add ]] && ! ((x%2)); then
            print -v graph_even[y] -t "${symbols[${prev_value}${cur_value}]}"
        else
            print -v graph_array[y] -t "${symbols[${prev_value}${cur_value}]}"
        fi

Expected behavior

Reducing script's system footprint.

aristocratos commented 2 years ago

@F-Hauri There's actually no need to set a custom numbering at all. Just multiply ${prev_value} by 5 and add ${cur_value} on that. See the current iteration of the graph creation code in https://github.com/aristocratos/btop/blob/main/src/btop_draw.cpp

F-Hauri commented 2 years ago

I agree, btop is a nice evolution of bashtop! Anyway, my remark does'nt concern btop, but only bashtop! Good work, sorry for disturbing...