diff options
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | MANIFEST | 18 | ||||
-rw-r--r-- | META.json | 2 | ||||
-rw-r--r-- | META.yml | 2 | ||||
-rw-r--r-- | Makefile.PL | 18 | ||||
-rw-r--r-- | bin/cdiff.pl (renamed from cdiff.pl) | 0 | ||||
-rw-r--r-- | bin/diff.pl (renamed from diff.pl) | 0 | ||||
-rw-r--r-- | bin/diffnew.pl (renamed from diffnew.pl) | 0 | ||||
-rw-r--r-- | bin/htmldiff.pl (renamed from htmldiff.pl) | 0 | ||||
-rw-r--r-- | lib/Algorithm/Diff.pm | 37 | ||||
-rw-r--r-- | lib/Algorithm/DiffOld.pm | 2 |
11 files changed, 46 insertions, 36 deletions
@@ -1,5 +1,8 @@ Revision history for Perl module Algorithm::Diff. +1.201 2020-12-13 + - speed up LCS when $keyGen is undef (RT 101105; thanks, XENU) + 1.200 2020-09-27 - new release with no new features, just preparing for a series of bugfix releases @@ -1,14 +1,14 @@ +bin/cdiff.pl +bin/diff.pl +bin/diffnew.pl +bin/htmldiff.pl Changes -lib/Algorithm/Diff.pm Algorithm::Diff perl module -lib/Algorithm/DiffOld.pm Algorithm::Diff perl module with old behavior +lib/Algorithm/Diff.pm +lib/Algorithm/DiffOld.pm Makefile.PL -MANIFEST +MANIFEST This list of files README -t/base.t Basic test script -t/oo.t OO interface test script -cdiff.pl Context diff utility -diff.pl Simple Unix diff utility written in Perl -diffnew.pl Full-featured Unix diff utility written in Perl -htmldiff.pl Sample using traverse_sequences +t/base.t +t/oo.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) @@ -32,6 +32,6 @@ } }, "release_status" : "stable", - "version" : "1.200", + "version" : "1.201", "x_serialization_backend" : "JSON::PP version 4.05" } @@ -17,5 +17,5 @@ no_index: directory: - t - inc -version: '1.200' +version: '1.201' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/Makefile.PL b/Makefile.PL index 253f1df..63b0ff8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,7 +1,17 @@ +use strict; +use warnings; + use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. + WriteMakefile( - 'NAME' => 'Algorithm::Diff', - 'VERSION_FROM' => 'lib/Algorithm/Diff.pm', # finds $VERSION + NAME => 'Algorithm::Diff', + VERSION_FROM => 'lib/Algorithm/Diff.pm', # finds $VERSION + + # Note that EXE_FILES is not provided. The programs shipped with + # Algorithm-Diff have traditionally not been installed to the $PATH, and are + # unlikely to get installed there in the future. + + META_ADD => { + license => 'http://dev.perl.org/licenses/', + }, ); diff --git a/diffnew.pl b/bin/diffnew.pl index 63591cd..63591cd 100644 --- a/diffnew.pl +++ b/bin/diffnew.pl diff --git a/htmldiff.pl b/bin/htmldiff.pl index fdc8102..fdc8102 100644 --- a/htmldiff.pl +++ b/bin/htmldiff.pl diff --git a/lib/Algorithm/Diff.pm b/lib/Algorithm/Diff.pm index 29dc8e5..93b3c79 100644 --- a/lib/Algorithm/Diff.pm +++ b/lib/Algorithm/Diff.pm @@ -5,7 +5,7 @@ use strict; use integer; # see below in _replaceNextLargerWith() for mod to make # if you don't use this use vars qw( $VERSION @EXPORT_OK ); -$VERSION = '1.200'; +$VERSION = '1.201'; require Exporter; *import = \&Exporter::import; @@ -40,7 +40,7 @@ sub _withPositionsOfInInterval for ( $index = $start ; $index <= $end ; $index++ ) { my $element = $aCollection->[$index]; - my $key = &$keyGen( $element, @_ ); + my $key = $keyGen ? &$keyGen( $element, @_ ) : $element; if ( exists( $d{$key} ) ) { unshift ( @{ $d{$key} }, $index ); @@ -145,12 +145,7 @@ sub _longestCommonSubsequence # set up code refs # Note that these are optimized. - if ( !defined($keyGen) ) # optimize for strings - { - $keyGen = sub { $_[0] }; - $compare = sub { my ( $a, $b ) = @_; $a eq $b }; - } - else + if ( $keyGen ) # optimize for strings { $compare = sub { my $a = shift; @@ -173,7 +168,8 @@ sub _longestCommonSubsequence # First we prune off any common elements at the beginning while ( $aStart <= $aFinish and $bStart <= $bFinish - and &$compare( $a->[$aStart], $b->[$bStart], @_ ) ) + and ( $keyGen ? &$compare( $a->[$aStart], $b->[$bStart], @_ ) + : ( $a->[$aStart] eq $b->[$bStart] ) ) ) { $matchVector->[ $aStart++ ] = $bStart++; $prunedCount++; @@ -182,7 +178,8 @@ sub _longestCommonSubsequence # now the end while ( $aStart <= $aFinish and $bStart <= $bFinish - and &$compare( $a->[$aFinish], $b->[$bFinish], @_ ) ) + and ( $keyGen ? &$compare( $a->[$aFinish], $b->[$bFinish], @_ ) + : ( $a->[$aFinish] eq $b->[$bFinish] ) ) ) { $matchVector->[ $aFinish-- ] = $bFinish--; $prunedCount++; @@ -198,7 +195,7 @@ sub _longestCommonSubsequence my ( $i, $ai, $j, $k ); for ( $i = $aStart ; $i <= $aFinish ; $i++ ) { - $ai = &$keyGen( $a->[$i], @_ ); + $ai = $keyGen ? &$keyGen( $a->[$i], @_ ) : $a->[$i]; if ( exists( $bMatches->{$ai} ) ) { $k = 0; @@ -973,8 +970,8 @@ Therefore, the following three lists will contain the same values: =head2 C<new> - $diff = Algorithm::Diffs->new( \@seq1, \@seq2 ); - $diff = Algorithm::Diffs->new( \@seq1, \@seq2, \%opts ); + $diff = Algorithm::Diff->new( \@seq1, \@seq2 ); + $diff = Algorithm::Diff->new( \@seq1, \@seq2, \%opts ); C<new> computes the smallest set of additions and deletions necessary to turn the first sequence into the second and compactly records them @@ -984,8 +981,6 @@ You use the object to iterate over I<hunks>, where each hunk represents a contiguous section of items which should be added, deleted, replaced, or left unchanged. -=over 4 - The following summary of all of the methods looks a lot like Perl code but some of the symbols have different meanings: @@ -1016,6 +1011,8 @@ is "reset" (not currently pointing at any hunk). Passing in C<undef> for an optional argument is always treated the same as if no argument were passed in. +=over 4 + =item C<Next> $pos = $diff->Next(); # Move forward 1 hunk @@ -1097,25 +1094,25 @@ follow 4 values: =over 4 -=item 3 +=item Z<>3 C<3==(1|2)>. This hunk contains items from @seq1 and the items from @seq2 that should replace them. Both sequence 1 and 2 contain changed items so both the 1 and 2 bits are set. -=item 2 +=item Z<>2 This hunk only contains items from @seq2 that should be inserted (not items from @seq1). Only sequence 2 contains changed items so only the 2 bit is set. -=item 1 +=item Z<>1 This hunk only contains items from @seq1 that should be deleted (not items from @seq2). Only sequence 1 contains changed items so only the 1 bit is set. -=item 0 +=item Z<>0 This means that the items in this hunk are the same in both sequences. Neither sequence 1 nor 2 contain changed items so neither the 1 nor the @@ -1687,7 +1684,7 @@ empty mail message to mjd-perl-diff-request@plover.com. Versions through 0.59 (and much of this documentation) were written by: -Mark-Jason Dominus, mjd-perl-diff@plover.com +Mark-Jason Dominus This version borrows some documentation and routine names from Mark-Jason's, but Diff.pm's code was completely replaced. diff --git a/lib/Algorithm/DiffOld.pm b/lib/Algorithm/DiffOld.pm index 57b508f..ae10c11 100644 --- a/lib/Algorithm/DiffOld.pm +++ b/lib/Algorithm/DiffOld.pm @@ -12,7 +12,7 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(LCS diff traverse_sequences); -$VERSION = '1.200'; # manually tracking Algorithm::Diff +$VERSION = '1.201'; # manually tracking Algorithm::Diff # McIlroy-Hunt diff algorithm # Adapted from the Smalltalk code of Mario I. Wolczko, <mario@wolczko.com> |