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

[SCM] Debian package checker branch, master, updated. 2.5.14-39-g2c62b73



The following commit has been merged in the master branch:
commit 2c62b7364fb513b2725eacfe5d72ac6450339366
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Jul 5 12:18:49 2013 +0200

    L::C::Package: Reuse (intern) some strings in index
    
    Reuse use the string used as key in the index fields instead of making
    a(n implicit) copy of it.  The memory saved varies greatly between the
    packages (e.g. source:lintian saves about 4% where as the
    binary:lintian only saves <1%).
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index 44062c9..7c78d42 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -57,6 +57,9 @@ lintian (2.5.15) UNRELEASED; urgency=low
       Devel::Size is available.  A more detailed breakdown
       of the memory usage with -dddd.
 
+  * lib/Lintian/Collect/Package.pm:
+    + [NT] Share some string values in index functions.  This
+      reduces memory usage a bit.
   * lib/Lintian/Collect/Source.pm:
     + [NT] "binaries" and "binary_field" now only exposes data
       about entries in d/control with a valid package name.
diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index df64017..17b2e4b 100644
--- a/lib/Lintian/Collect/Package.pm
+++ b/lib/Lintian/Collect/Package.pm
@@ -351,7 +351,7 @@ sub _fetch_index_data {
             ($name, $file{link}) = split ' -> ', $name, 2;
             $file{link} = _dequote_name ($file{link}, 0);
         }
-        $file{name} = $name = _dequote_name ($name);
+        $name = _dequote_name($name);
 
         $idxh{$name} = \%file;
 
@@ -360,8 +360,11 @@ sub _fetch_index_data {
         my ($parent, $base) = ($name =~ m,^(.+/)?([^/]+/?)$,);
         $parent = '' unless defined $parent;
         $base = '' unless defined $base;
-        $file{dirname} = $parent;
         $file{basename} = $base;
+        # Insert the dirname field later for all (non-root) entries as
+        # it allows us to better reuse memory.
+        $file{dirname} = '' if $base eq '';
+
         $children{$parent} = [] unless exists $children{$parent};
         # Ensure the "root" is not its own child.  It is not really helpful
         # from an analysis PoV and it creates ref cycles  (and by extension
@@ -417,8 +420,18 @@ 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') {
-            $idxh{$file}->{children} = [ map { $idxh{$_} } sort @{ $children{$file} } ];
+            my @children;
+            for my $cname (sort(@{ $children{$file} })) {
+                my $child = $idxh{$cname};
+                # Insert dirname here to share the same storage with
+                # the hash key
+                $child->{'dirname'} = $file;
+                push(@children, $child);
+            }
+            $idxh{$file}{children} = \@children;
         }
+        # Insert name here to share the same storage with the hash key
+        $idxh{$file}{'name'} = $file;
         $idxh{$file} = Lintian::Path->new ($idxh{$file});
     }
     $self->{$field} = \%idxh;

-- 
Debian package checker


Reply to: