[pacman-dev] [PATCH 4/6] pacsearch: removed redundant sorting
Andrew Gregory
andrew.gregory.8 at gmail.com
Mon Feb 3 07:34:22 EST 2014
On 02/03/14 at 12:36pm, Pierre Neidhardt wrote:
> Package are processed in the same order as pacman output, so there is no need to
> sort, we can print directly. This makes the code simpler and faster.
>
> The only difference is that local packages will always be printed at the
> end. Previously, they were printe before multilib for instance.
>
> Signed-off-by: Pierre Neidhardt <ambrevar at gmail.com>
> ---
> contrib/pacsearch.in | 44 ++++++++++++++++----------------------------
> 1 file changed, 16 insertions(+), 28 deletions(-)
This will cause a large delay between printing sync and local results on first
runs.
> diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in
> index 5ca2cfd..d1a19d6 100644
> --- a/contrib/pacsearch.in
> +++ b/contrib/pacsearch.in
> @@ -81,21 +81,21 @@ if ($ARGV[0] eq "--nocolor" || $ARGV[0] eq "-n") {
> # localization
> my $LC_INSTALLED = `gettext pacman installed`;
>
> -# Color a "repo/pkgname pkgver (groups) [installed]" line.
> -# We try to stick to pacman colors.
> -sub to_color {
> +# Print a "repo/pkgname pkgver (groups) [installed]" line.
> +# We stick to pacman colors.
> +sub print_pkg {
> my @v = @_;
> - my $line = "$RESET$BOLD";
> + print "$RESET$BOLD";
> if ( "$v[0]" eq "local" ) {
> - $line .= "$RED";
> + print "$RED";
> } else {
> - $line .= "$MAGENTA";
> + print "$MAGENTA";
> }
> - $line .= "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]";
> - $line .= " $BLUE$v[3]" if $v[3] ne "";
> - $line .= " $CYAN$v[4]" if $v[4] ne "";
> - $line .= " $RESET";
> - return $line;
> + print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]";
> + print " $BLUE$v[3]" if $v[3] ne "";
> + print " $CYAN$v[4]" if $v[4] ne "";
> + print " $RESET\n";
> + print " $v[5]\n";
> }
>
> my %allpkgs = ();
> @@ -121,10 +121,10 @@ foreach $_ (@syncpkgs) {
> # since 'group' and 'installed' are optional, we should fill it in if necessary
> $pkgfields[3] = "" if not defined $pkgfields[3];
> $pkgfields[4] = "" if not defined $pkgfields[4];
> - # add a last field that indicates original order
> - push (@pkgfields, $cnt++);
> - # add each sync pkg by name/ver to a hash table for quick lookup
> - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ];
> + # Add each sync pkg by name/ver to a hash table.
> + # Any value is good since we only check for existence.
> + $allpkgs{$pkgfields[1] . $pkgfields[2]} = 1;
> + print_pkg(@pkgfields);
> }
>
> my $queryout = `pacman -Qs @ARGV`;
> @@ -145,20 +145,8 @@ foreach $_ (@querypkgs) {
> # since 'group' is optional, we should fill it in if necessary
> $pkgfields[3] = "" if not defined $pkgfields[3];
> $pkgfields[4] = "[$LC_INSTALLED]";
> - # add a last field that indicates original order (after sync)
> - push (@pkgfields, $cnt++);
> - # add our local-only package to the hash
> - $allpkgs{$pkgfields[1] . $pkgfields[2]} = [ @pkgfields ];
> + print_pkg(@pkgfields);
> }
> }
>
> -# sort by original order (the last field) and print
> -foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) {
> - my @v = @{$allpkgs{$_}};
> - my $line = to_color(@v);
> - # print colorized "repo/pkgname pkgver ..." string with possible installed text
> - print "$line\n";
> - print "$v[5]\n";
> -}
> -
> #vim: set noet:
> --
> 1.8.5.3
>
>
More information about the pacman-dev
mailing list