aboutsummaryrefslogtreecommitdiff
path: root/checkem
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-08-04 13:28:32 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-08-04 13:28:32 +1200
commite416b00792abf02b9fd552620205aebaddfa2e5e (patch)
tree536b0eda7cadf618f9c1457adb57eddb5e442bcf /checkem
parentUse slightly clearer bitwise ops (diff)
downloadcheckem-e416b00792abf02b9fd552620205aebaddfa2e5e.tar.gz (sig)
checkem-e416b00792abf02b9fd552620205aebaddfa2e5e.zip
Junk File::statv2.2
Seems to be a hotspot for speed and it's too easily worked around to keep
Diffstat (limited to 'checkem')
-rwxr-xr-xcheckem24
1 files changed, 16 insertions, 8 deletions
diff --git a/checkem b/checkem
index fe20e5c..c76be6e 100755
--- a/checkem
+++ b/checkem
@@ -12,7 +12,6 @@ use utf8;
use Carp;
use Fcntl ':mode';
use File::Find;
-use File::stat;
use Digest::SHA;
# Lowest version number that has all of those core modules; Digest::SHA is the
@@ -20,11 +19,20 @@ use Digest::SHA;
use 5.009003;
# Version number to make Perl::Critic happy
-our $VERSION = 2.1;
+our $VERSION = 2.2;
# If no arguments, work with the current working directory
croak('Need at least one dir to search') if !@ARGV;
+# Convenience keys into stat() return array for clarity and to appease
+# Perl::Critic
+my %STATS = (
+ dev => 0,
+ ino => 1,
+ mode => 2,
+ size => 7,
+);
+
# Start a hash of filesizes to file names/stats...
my %sizes;
@@ -33,13 +41,13 @@ find {
no_chdir => 1,
wanted => sub {
my $fn = $File::Find::name;
- my $st = stat $fn or return;
- return if !( $st->mode & S_IFREG );
- return if !$st->size;
- push @{ $sizes{ $st->size } },
+ my @st = stat $fn or return;
+ return if !( $st[ $STATS{mode} ] & S_IFREG );
+ return if !$st[ $STATS{size} ];
+ push @{ $sizes{ $st[ $STATS{size} ] } },
{
fn => $fn,
- st => $st,
+ st => \@st,
};
return;
},
@@ -57,7 +65,7 @@ FS: for my $fs ( grep { @{$_} > 1 } values %sizes ) {
F: for my $f ( @{$fs} ) {
# Catch hard links on compliant systems by keeping a dev/inode hash
- my ( $dev, $ino ) = ( $f->{st}->dev, $f->{st}->ino );
+ my ( $dev, $ino ) = ( @{ $f->{st} }[ @STATS{qw(dev ino)} ] );
if ( $dev && $ino ) {
next F if exists $inos{$dev}{$ino};
$inos{$dev}{$ino} = $f;