[pacman-dev] [PATCH] Remove use of `seq` in pactree

Dan McGee dpmcgee at gmail.com
Thu Oct 7 17:16:50 EDT 2010


On Thu, Oct 7, 2010 at 4:03 PM, Dave Reisner <d at falconindy.com> wrote:
> On Thu, Oct 07, 2010 at 03:52:34PM -0500, Dan McGee wrote:
>> This is not a bash builtin, so can potentially cause portability issues.
>> Additionally, the use of it is completely unnecessary as it can all be done
>> within bash (and done faster).
>>
>> $ time pactree xfwm4 >/dev/null (old version)
>> real  0m3.245s
>>
>> $ time ./contrib/pactree xfwm4 >/dev/null (new version)
>> real  0m3.042s
>>
>> Signed-off-by: Dan McGee <dan at archlinux.org>
>> ---
>>  contrib/pactree |    5 ++++-
>>  1 files changed, 4 insertions(+), 1 deletions(-)
>>
>> diff --git a/contrib/pactree b/contrib/pactree
>> index 73bece3..cb719f3 100755
>> --- a/contrib/pactree
>> +++ b/contrib/pactree
>> @@ -130,9 +130,12 @@ _tree(){
>>
>>               # Generate the spacer
>>               spacer=""
>> -             for each in $(seq 1 $spaces); do
>> +             local count=0
>> +             while [[ $count -lt $spaces ]]; do
>>                       spacer="$spacer$separator"
>> +                     count=$((count+1))
>>               done
>> +             unset count
>>               spacer="$spacer$branch_tip"
>>
>>               [ $silent -ne 1 ] &&    echo -e "$branch_color$spacer$leaf_color$pkg_name$provided"
>> --
>> 1.7.3.1
>>
>>
>
> Can I suggest using a C style for loop instead?
>
> for (( count=0; count < spaces; count++ )); do
>  # stuff...
> done
> unset count

Definitely, adjusted the patch. Thanks.

-Dan


More information about the pacman-dev mailing list