[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#605844: lintian: Consider pre-sorting keys %{$info->index}



Interestingly enough this does not appear to be the current bottle
neck of lintian (or I am doing something wrong in my patch).

~Niels

$ dpkg --contents eclipse-platform-data_3.5.2-8_all.deb  | wc -l
1480

lintian 2.4.3
$ for i in {1..5} ; do time lintian -EI --pedantic
eclipse-platform-data_3.5.2-8_all.deb  ; done

real    0m9.170s
user    0m4.556s
sys     0m0.908s

real    0m9.083s
user    0m4.628s
sys     0m0.868s

real    0m10.285s
user    0m4.600s
sys     0m0.928s

real    0m9.762s
user    0m4.524s
sys     0m0.972s

real    0m8.833s
user    0m4.624s
sys     0m0.864s

lintian 2.4.4 (from git with patch)
$ for i in {1..5} ; do time lintian -EI --pedantic
eclipse-platform-data_3.5.2-8_all.deb  ; done

real    0m7.659s
user    0m4.484s
sys     0m1.024s

real    0m9.412s
user    0m4.556s
sys     0m0.944s

real    0m8.672s
user    0m4.496s
sys     0m0.992s

real    0m9.090s
user    0m4.496s
sys     0m0.976s

real    0m9.000s
user    0m4.460s
sys     0m1.052s
diff --git a/checks/changelog-file b/checks/changelog-file
index 8147095..40f4b0f 100644
--- a/checks/changelog-file
+++ b/checks/changelog-file
@@ -79,7 +79,7 @@ for my $file (sort keys %{$info->file_info}) {
 }
 
 # Read package contents....  Capitalization errors are dealt with later.
-foreach (sort keys %{$info->index}) {
+foreach (@{$info->sorted_index}) {
     next unless length $_;
     # skip packages which have a /usr/share/doc/$pkg -> foo symlink
     if (m,usr/share/doc/$ppkg$, and defined $info->index->{$_}->{link}) {
diff --git a/checks/copyright-file b/checks/copyright-file
index 336d0f4..267ed43 100644
--- a/checks/copyright-file
+++ b/checks/copyright-file
@@ -45,7 +45,7 @@ my $found = 0;
 my $linked = 0;
 
 # Read package contents...
-foreach (sort keys %{$info->index}) {
+foreach (@{$info->sorted_index}) {
     my $index_info = $info->index->{$_};
     if (m,usr/(share/)?doc/$ppkg/copyright(\.\S+)?$,) {
 	my $ext = $2;
diff --git a/checks/etcfiles b/checks/etcfiles
index bc61715..9a734b1 100644
--- a/checks/etcfiles
+++ b/checks/etcfiles
@@ -45,7 +45,7 @@ if (open(IN, '<', $conffiles)) {
 }
 
 # Read package contents...
-foreach my $file (sort keys %{$info->index}) {
+foreach my $file (@{$info->sorted_index}) {
     my $index_info = $info->index->{$file};
     next unless $file =~ m,^etc, and $index_info->{type}=~ m/^[-h]/;
 
diff --git a/checks/fields b/checks/fields
index e5f7108..848e9ac 100644
--- a/checks/fields
+++ b/checks/fields
@@ -503,7 +503,7 @@ if (defined $info->field('installer-menu-item')) {
 my $metapackage = 0;
 if ($type eq 'binary') {
 	$metapackage = 1;
-	for my $file (keys %{$info->index}) {
+	for my $file (@{$info->sorted_index}) {
 		next if $info->index->{$file}->{type} =~ /^d/;
 		next if $file =~ m%^usr/share/doc/%;
 		next if $file =~ m%^usr/share/lintian/overrides/%;
diff --git a/checks/files b/checks/files
index 56cf40b..aa140dc 100644
--- a/checks/files
+++ b/checks/files
@@ -199,7 +199,7 @@ if ($description) {
     }
 }
 if ($is_empty) {
-    for my $file (sort keys %{$info->index}) {
+    for my $file (@{$info->sorted_index}) {
         # Ignore directories
         unless ($file =~ m,/$,) {
             # Skip if $file is an empty string
@@ -226,7 +226,7 @@ if ($is_empty) {
 }
 
 # Read package contents...
-foreach my $file (sort keys %{$info->index}) {
+foreach my $file (@{$info->sorted_index}) {
     next if $file eq "";
     my $index_info = $info->index->{$file};
     my $owner = $index_info->{owner} . '/' . $index_info->{group};
@@ -1204,7 +1204,7 @@ if ($pkg_section !~ m,games$, and $games > 0 and $other == 0) {
 # so just ignore them.
 #
 # python-support needs a directory for each package even it might be empty
-foreach my $dir (sort keys %{$info->index}) {
+foreach my $dir (@{$info->sorted_index}) {
     next if $dir eq "" or $info->index->{$dir}->{type} ne 'd';
     next if ($dir =~ m{^var/} or $dir =~ m{^etc/});
     next if $pkg eq 'base-files';
diff --git a/checks/infofiles b/checks/infofiles
index 2c5b994..872a74b 100644
--- a/checks/infofiles
+++ b/checks/infofiles
@@ -40,7 +40,7 @@ my %missing_section;
 my $has_info_file;
 
 # Read package contents...
-foreach my $file (sort keys %{$info->index}) {
+foreach my $file (@{$info->sorted_index}) {
     my $index_info = $info->index->{$file};
     my $file_info = $info->file_info->{$file};
     my $link = $index_info->{link} || '';
diff --git a/checks/manpages b/checks/manpages
index 0035bda..17912d2 100644
--- a/checks/manpages
+++ b/checks/manpages
@@ -40,7 +40,7 @@ my %link;
 my %manpage;
 
 # Read package contents...
-foreach my $file (sort keys %{$info->index}) {
+foreach my $file (@{$info->sorted_index}) {
     my $index_info = $info->index->{$file};
     my $file_info = $info->file_info->{$file};
     my $link = $index_info->{link} || '';
diff --git a/checks/menu-format b/checks/menu-format
index bbb4bc8..4e85dae 100644
--- a/checks/menu-format
+++ b/checks/menu-format
@@ -396,7 +396,7 @@ closedir MENUDIR;
 
 # Find the desktop files in the package for verification.
 my @desktop_files;
-foreach my $file (sort keys %{$info->index}) {
+foreach my $file (@{$info->sorted_index}) {
     my $index_info = $info->index->{$file};
     my $operm = $index_info->{operm};
 
diff --git a/checks/scripts b/checks/scripts
index 54aa37b..1acd2b0 100644
--- a/checks/scripts
+++ b/checks/scripts
@@ -312,7 +312,7 @@ my $pkg = shift;
 my $type = shift;
 my $info = shift;
 
-foreach (sort keys %{$info->index}) {
+foreach (@{$info->sorted_index}) {
     next if $_ eq "";
     my $index_info = $info->index->{$_};
     my $operm = $index_info->{operm};
@@ -1114,7 +1114,7 @@ for my $divert (keys %added_diversions) {
 
     if ($expand_diversions) {
 	tag 'diversion-for-unknown-file', $divert, "$script:$line"
-	    unless (grep { $_ =~ m/$divertrx/ } keys %{$info->index});
+	    unless (grep { $_ =~ m/$divertrx/ } @{$info->sorted_index});
     } else {
 	tag 'diversion-for-unknown-file', $divert, "$script:$line"
 	    unless (exists $info->index->{$divert});
diff --git a/checks/shared-libs b/checks/shared-libs
index 1450f4b..b266ba5 100644
--- a/checks/shared-libs
+++ b/checks/shared-libs
@@ -83,7 +83,7 @@ foreach my $file (sort keys %{$info->file_info}) {
 
 # 2nd step: read package contents
 
-for my $cur_file (sort keys %{$info->index}) {
+for my $cur_file (@{$info->sorted_index}) {
     # shared library?
     my $cur_file_data = $info->index->{$cur_file};
 
diff --git a/lib/Lintian/Collect/Binary.pm b/lib/Lintian/Collect/Binary.pm
index 6b6feeb..bc297fb 100644
--- a/lib/Lintian/Collect/Binary.pm
+++ b/lib/Lintian/Collect/Binary.pm
@@ -122,6 +122,18 @@ sub index {
     return $self->{index};
 }
 
+# Returns sorted file index (eqv to sort keys %{$info->index}), except it is cached.
+sub sorted_index {
+    my ($self) = @_;
+    my $index;
+    my @result;
+    return $self->{sorted_index} if exists $self->{sorted_index};
+    $index = $self->index();
+    @result = sort keys %{$index};
+    $self->{sorted_index} = \@result;
+    return \@result;
+}
+
 # Returns the information from collect/file-info
 sub file_info {
     my ($self) = @_;

Reply to: