Skip to content

Commit

Permalink
diff: reduce code noise (#458)
Browse files Browse the repository at this point in the history
* Mapping loop is more direct to write with map()
* Check for error instead of success in output_diff()
* Tested this with -e, -f and -u flags on some small files
  • Loading branch information
mknos authored Feb 13, 2024
1 parent fe33133 commit 2dab6c4
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions bin/diff
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,8 @@ sub output_diff {
"REVERSE_ED" => \&output_ed_diff,
"UNIFIED" => \&output_unified_diff,
);
if (exists $funchash{$diff_type}) {
&{$funchash{$diff_type}}(@_); # pass in all args
} else {die "unknown diff type $diff_type"}
my $func = $funchash{$diff_type} or die "unknown diff type '$diff_type'\n";
$func->(@_);
}

sub output_old_diff {
Expand Down Expand Up @@ -538,15 +537,8 @@ sub new {
# We don't bother storing the text of the item
#
my ($class,$chunk) = @_;
my @changes = ();

# This just turns each change into a hash.
foreach my $item (@$chunk) {
my ($sign, $item_no, $text) = @$item;
my $hashref = {"sign" => $sign, "item_no" => $item_no};
push @changes, $hashref;
}

my @changes = map { {'sign' => $_->[0], 'item_no' => $_->[1]} } @$chunk;
my $block = { "changes" => \@changes };
bless $block, $class;

Expand Down

0 comments on commit 2dab6c4

Please sign in to comment.