From 971e3f39b0864cc1ce745b1d8c039267b82f02a5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 4 Aug 2017 14:52:51 +1200 Subject: Load up only required stat() fields --- checkem | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'checkem') diff --git a/checkem b/checkem index 43573da..be91194 100755 --- a/checkem +++ b/checkem @@ -24,7 +24,7 @@ use Digest::SHA; use 5.009003; # Version number to make Perl::Critic happy -our $VERSION = 2.3; +our $VERSION = 2.4; # If no arguments, work with the current working directory croak('Need at least one dir to search') if !@ARGV; @@ -51,13 +51,15 @@ find { no_chdir => 1, wanted => sub { my $fn = $File::Find::name; - my @st = stat $fn or return; - return if !( $st[ $STATS{mode} ] & S_IFREG ); - return if !$st[ $STATS{size} ]; - return push @{ $sizes{ $st[ $STATS{size} ] } }, + my %st; + @st{ keys %STATS } = ( stat $fn )[ values %STATS ] + or return; + return if !( $st{mode} & S_IFREG ); + return if !$st{size}; + return push @{ $sizes{ $st{size} } }, { fn => $fn, - st => \@st, + st => \%st, }; }, }, @ARGV; @@ -74,7 +76,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} }[ @STATS{qw(dev ino)} ]; + my ( $dev, $ino ) = @{ $f->{st} }{qw(dev ino)}; if ( $dev && $ino ) { next F if exists $inos{$dev}{$ino}; $inos{$dev}{$ino} = $f; -- cgit v1.2.3