[lintian] 02/03: L::Path: Compute basename instead of having it as a field
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit a6961972264aa5de9e9a7fa12ff8f01b73ad37e4
Author: Niels Thykier <niels@thykier.net>
Date: Fri Jul 17 19:45:13 2015 +0200
L::Path: Compute basename instead of having it as a field
This saves an additional 3.2% cached memory when processing lintian.
Signed-off-by: Niels Thykier <niels@thykier.net>
---
lib/Lintian/Collect/Package.pm | 6 +-----
lib/Lintian/Path.pm | 18 +++++++++++++++++-
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/lib/Lintian/Collect/Package.pm b/lib/Lintian/Collect/Package.pm
index 0cbd283..2968df2 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,
- 'basename' => '',
'owner' => 'root',
'group' => 'root',
'size' => 0,
@@ -493,7 +492,6 @@ sub _fetch_index_data {
my ($parent, $base) = ($name =~ m,^(.+/)?([^/]+/?)$,);
$parent = '' unless defined $parent;
$base = '' unless defined $base;
- $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 '';
@@ -515,11 +513,9 @@ sub _fetch_index_data {
# check_dirs /can/ contain the same item multiple times.
if (!exists($idxh{$name})) {
my %cpy = %INDEX_FAUX_DIR_TEMPLATE;
- my ($parent, $base) = ($name =~ m,^(.+/)?([^/]+/?)$,);
+ my ($parent) = ($name =~ m,^(.+/)?(?:[^/]+/?)$,);
$parent //= '';
- $base //= '';
$cpy{'name'} = $name;
- $cpy{'basename'} = $base;
# Re: above, only insert dirname now for the root entry.
$cpy{'dirname'} = q{} if $name eq q{};
if ($num_idx) {
diff --git a/lib/Lintian/Path.pm b/lib/Lintian/Path.pm
index 225cac7..240555d 100644
--- a/lib/Lintian/Path.pm
+++ b/lib/Lintian/Path.pm
@@ -197,6 +197,22 @@ for the "root" dir - see below).
NB: Returns the empty string for the "root" dir.
+=cut
+
+sub basename {
+ my ($self) = @_;
+ my $name = $self->name;
+ my $slash;
+ return $name if $name eq q{}; # Root dir
+ if (substr($name, -1, 1) eq '/') {
+ $slash = rindex($name, '/', length($name) - 2);
+ } else {
+ $slash = rindex($name, '/');
+ }
+ return $name if $slash == -1; # E.g. Top level-dirs
+ return substr($name, $slash+1);
+}
+
=item faux
Returns a truth value if this entry absent in the package. This can
@@ -206,7 +222,7 @@ happen if a package does not include all intermediate directories.
Lintian::Path->mk_ro_accessors(
qw(name owner group link uid gid
- size date time parent_dir dirname basename
+ size date time parent_dir dirname
faux
));
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: