[lintian] 02/04: L::Path: Drop size field when size is 0 or not a file
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit 5cd2c2b48ea214af6835aa56174ad3b49d3efba8
Author: Niels Thykier <niels@thykier.net>
Date: Sun Jul 19 23:49:11 2015 +0200
L::Path: Drop size field when size is 0 or not a file
Only store the file-size when:
* it is non-zero
* the path is a regular file
This brings another 0.17MB memory savings on memory size of the
caches, when processing lintian.
Signed-off-by: Niels Thykier <niels@thykier.net>
---
lib/Lintian/Collect/Package.pm | 17 ++++++++++++-----
lib/Lintian/Path.pm | 12 ++++++++++--
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index 0910965..b4e85b9 100644
--- a/lib/Lintian/Collect/Package.pm
+++ b/lib/Lintian/Collect/Package.pm
@@ -57,7 +57,6 @@ my %FILE_CODE2LPATH_TYPE = (
my %INDEX_FAUX_DIR_TEMPLATE = (
'name' => '',
'_path_info' => $FILE_CODE2LPATH_TYPE{'d'} | 0755,
- 'size' => 0,
# Pick a "random" (but fixed) date
# - hint, it's a good read. :)
'date' => '1998-01-25',
@@ -435,9 +434,17 @@ sub _fetch_index_data {
while (my $line = <$idx>) {
chomp($line);
- my (%file, $perm, $operm, $ownership, $name, $raw_type);
- ($perm,$ownership,$file{size},$file{date},$file{time},$name)
+ my (%file, $perm, $operm, $ownership, $name, $raw_type, $size);
+ ($perm,$ownership,$size,$file{date},$file{time},$name)
=split(' ', $line, 6);
+
+ $raw_type = substr($perm, 0, 1);
+
+ # Only set size if it is non-zero and even then, only for
+ # regular files. When we set it, insist on it being an int.
+ # This makes perl store it slightly more effecient.
+ $file{'size'} = int($size) if $size and $raw_type eq '-';
+
# This may appear to be obscene, but the call overhead of
# perm2oct is measurable on (e.g.) chromium-browser. With
# the cache we go from ~1.5s to ~0.1s.
@@ -448,7 +455,6 @@ sub _fetch_index_data {
} else {
$operm = perm2oct($perm);
}
- $raw_type = substr($perm, 0, 1);
$file{'_path_info'} = $operm
| ($FILE_CODE2LPATH_TYPE{$raw_type} // Lintian::Path::TYPE_OTHER);
@@ -575,7 +581,8 @@ sub _fetch_index_data {
| Lintian::Path::TYPE_FILE;
# hardlinks does not have size, so copy that from the original
# entry.
- $idxh{$target}->{size} = $e->{size};
+ $idxh{$target}{'size'} = $e->{'size'} if exists($e->{'size'});
+ delete($e->{'size'});
delete $idxh{$target}->{link};
}
}
diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index 940bf51..e0119b8 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -199,7 +199,15 @@ NB: Even for symlinks, a leading "./" will be stripped.
Returns the size of the path in bytes.
-NB: This is only well defined for files.
+NB: Only regular files can have a non-zero file size.
+
+=cut
+
+sub size {
+ my ($self) = @_;
+ return 0 if not exists($self->{'size'});
+ return $self->{'size'};
+}
=item date
@@ -262,7 +270,7 @@ happen if a package does not include all intermediate directories.
=cut
Lintian::Path->mk_ro_accessors(
- qw(name link size date time parent_dir faux
+ qw(name link date time parent_dir faux
));
=item operm
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: