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

[lintian] 01/01: L::Path: Precompute "sorted children"



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit ec66a1dacbe793b20b9daf7980fbb69d3ce26299
Author: Niels Thykier <niels@thykier.net>
Date:   Thu Oct 2 21:43:54 2014 +0200

    L::Path: Precompute "sorted children"
    
    It saves ~0.2 seconds when processing Lintian.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 lib/Lintian/Collect/Package.pm |  5 ++++-
 lib/Lintian/Path.pm            | 16 ++++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index 778771e..fd175a6 100644
--- a/lib/Lintian/Collect/Package.pm
+++ b/lib/Lintian/Collect/Package.pm
@@ -552,7 +552,7 @@ sub _fetch_index_data {
         # Add them in reverse order - entries in a dir are made
         # objects before the dir itself.
         if ($idxh{$file}->{type} eq 'd') {
-            my %child_table;
+            my (%child_table, @sorted_children);
             for my $cname (sort(@{ $children{$file} })) {
                 my $child = $idxh{$cname};
                 my $basename = $child->basename;
@@ -563,7 +563,10 @@ sub _fetch_index_data {
                     $basename = substr($basename, 0, -1);
                 }
                 $child_table{$basename} = $child;
+                push(@sorted_children, $child);
             }
+            @sorted_children = reverse(@sorted_children);
+            $idxh{$file}{_sorted_children} = \@sorted_children;
             $idxh{$file}{children} = \%child_table;
         }
         # Insert name here to share the same storage with the hash key
diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index 0f54d06..1bbaf96 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -84,13 +84,14 @@ sub new {
         %$data,
     };
     bless($self, $type);
-    if ($self->is_file or $self->is_dir) {
-        $self->{'_is_open_ok'} = $self->is_file;
+    if ($self->is_file) {
+        $self->{'_is_open_ok'} = 1;
         $self->{'_valid_path'} = 1;
-        if ($self->is_dir) {
-            for my $child ($self->children) {
-                $child->_set_parent_dir($self);
-            }
+    } elsif ($self->is_dir) {
+        $self->{'_is_open_ok'} = 0;
+        $self->{'_valid_path'} = 1;
+        for my $child ($self->children) {
+            $child->_set_parent_dir($self);
         }
     }
     return $self;
@@ -207,8 +208,7 @@ NB: Returns the empty list for non-dir entries.
 
 sub children {
     my ($self) = @_;
-    return sort(values(%{ $self->{'children'} })) if wantarray;
-    return values(%{ $self->{'children'} });
+    return @{$self->{'_sorted_children'} };
 }
 
 =item child(BASENAME)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: