diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-08-09 15:55:22 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-08-09 15:55:22 +1200 |
commit | 045eb0fce48cfde291938d1232a5c90246b2b7fd (patch) | |
tree | 77bc8bdea44c6094b12f79c7694b15292945038a | |
parent | Add janky test suite (diff) | |
download | checkem-045eb0fce48cfde291938d1232a5c90246b2b7fd.tar.gz (sig) checkem-045eb0fce48cfde291938d1232a5c90246b2b7fd.zip |
Remove a layer of indirectionv2.7
Make things a little quicker by putting the name and stat values into
the same hash
-rwxr-xr-x | checkem | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -24,7 +24,7 @@ use Digest::SHA; use 5.009003; # Version number to make Perl::Critic happy -our $VERSION = 2.6; +our $VERSION = 2.7; # If no arguments, work with the current working directory if ( !@ARGV ) { @@ -54,25 +54,25 @@ my %sizes; find { no_chdir => 1, wanted => sub { - my $fn = $File::Find::name; - # Keep only the stat values we will actually need - my %st; - @st{ keys %STATS } = ( stat $fn )[ values %STATS ] + # Start a hash to represent this file + my %f; + + # Put the found name into it + $f{name} = $File::Find::name; + + # Pull in the file stat values we care about + @f{ keys %STATS } = ( stat $f{name} )[ values %STATS ] or return; # Check it's a regular file - return if not $st{mode} & S_IFREG; + return if not $f{mode} & S_IFREG; # Check its size is non-zero - return if not $st{size}; - - # Push the filename and the stats into this size's bucket - return push @{ $sizes{ $st{size} } }, - { - fn => $fn, - st => \%st, - }; + return if not $f{size}; + + # Push the file hash into its size's bucket + return push @{ $sizes{ $f{size} } }, \%f; }, }, @ARGV; @@ -88,7 +88,7 @@ for my $fs ( grep { @{$_} > 1 } values %sizes ) { for my $f ( @{$fs} ) { # Catch hard links on compliant systems by keeping a dev/inode hash - my ( $dev, $ino ) = @{ $f->{st} }{qw(dev ino)}; + my ( $dev, $ino ) = @{$f}{qw(dev ino)}; if ( $dev && $ino ) { next if exists $inos{$dev}{$ino}; $inos{$dev}{$ino} = $f; @@ -96,7 +96,7 @@ for my $fs ( grep { @{$_} > 1 } values %sizes ) { # Files still the same size and not hard linked, group by digest; # create the digest object if it isn't already defined - ( $dig //= Digest::SHA->new($alg) )->addfile( $f->{fn} ); + ( $dig //= Digest::SHA->new($alg) )->addfile( $f->{name} ); push @{ $sums{ $dig->digest() } }, $f; } } @@ -104,5 +104,5 @@ for my $fs ( grep { @{$_} > 1 } values %sizes ) { # Print the groups of matched files (more than one share a checksum in the # final table) for my $group ( grep { @{$_} > 1 } values %sums ) { - printf "%s\n\n", join "\n", map { $_->{fn} } @{$group}; + printf "%s\n\n", join "\n", map { $_->{name} } @{$group}; } |