Файловый менеджер - Редактировать - /var/www/html/Diff.zip
Ðазад
PK ! )Z��� � XS.pmnu �[��� package Algorithm::Diff::XS; use 5.006; use strict; use warnings; use vars '$VERSION'; use Algorithm::Diff; BEGIN { $VERSION = '0.04'; require XSLoader; XSLoader::load( __PACKAGE__, $VERSION ); my $code = do { open my $fh, '<', $INC{'Algorithm/Diff.pm'} or die "Cannot read $INC{'Algorithm/Diff.pm'}: $!"; local $/; <$fh>; }; { no warnings; local $@; $code =~ s/Algorithm::Diff/Algorithm::Diff::XS/g; $code =~ s/sub LCSidx/sub LCSidx_old/g; $code = "#line 1 " . __FILE__ . "\n$code"; eval $code; die $@ if $@; } no warnings 'redefine'; sub LCSidx { my $lcs = Algorithm::Diff::XS->_CREATE_; my ( @l, @r ); for my $chunk ( $lcs->_LCS_(@_) ) { push @l, $chunk->[0]; push @r, $chunk->[1]; } return ( \@l, \@r ); } } sub _line_map_ { my $ctx = shift; my %lines; push @{ $lines{ $_[$_] } }, $_ for 0 .. $#_; # values MUST be SvIOK \%lines; } sub _LCS_ { my ( $ctx, $a, $b ) = @_; my ( $amin, $amax, $bmin, $bmax ) = ( 0, $#$a, 0, $#$b ); while ( $amin <= $amax and $bmin <= $bmax and $a->[$amin] eq $b->[$bmin] ) { $amin++; $bmin++; } while ( $amin <= $amax and $bmin <= $bmax and $a->[$amax] eq $b->[$bmax] ) { $amax--; $bmax--; } my $h = $ctx->_line_map_( @$b[ $bmin .. $bmax ] ); # line numbers are off by $bmin return $amin + _core_loop_( $ctx, $a, $amin, $amax, $h ) + ( $#$a - $amax ) unless wantarray; my @lcs = _core_loop_( $ctx, $a, $amin, $amax, $h ); if ( $bmin > 0 ) { $_->[1] += $bmin for @lcs; # correct line numbers } map( [ $_ => $_ ], 0 .. ( $amin - 1 ) ), @lcs, map( [ $_ => ++$bmax ], ( $amax + 1 ) .. $#$a ); } 1; __END__ =head1 NAME Algorithm::Diff::XS - Algorithm::Diff with XS core loop =head1 SYNOPSIS # Drop-in replacement to Algorithm::Diff, but "compact_diff" # and C<LCSidx> will run much faster for large data sets. use Algorithm::Diff::XS qw( compact_diff LCSidx ); =head1 DESCRIPTION This module is a simple re-packaging of Joe Schaefer's excellent but not very well-known L<Algorithm::LCS> with a drop-in interface that simply re-uses the installed version of the L<Algorithm::Diff> module. Note that only the C<LCSidx> function is optimized in XS at the moment, which means only C<compact_diff> will get significantly faster for large data sets, while C<diff> and C<sdiff> will run in identical speed as C<Algorithm::Diff>. =head1 BENCHMARK Rate Algorithm::Diff Algorithm::Diff::XS Algorithm::Diff 14.7/s -- -98% Algorithm::Diff::XS 806/s 5402% -- The benchmarking script is as below: my @data = ([qw/a b d/ x 50], [qw/b a d c/ x 50]); cmpthese( 500, { 'Algorithm::Diff' => sub { Algorithm::Diff::compact_diff(@data) }, 'Algorithm::Diff::XS' => sub { Algorithm::Diff::XS::compact_diff(@data) }, }); =head1 SEE ALSO L<Algorithm::Diff>, L<Algorithm::LCS>. =head1 AUTHORS Audrey Tang E<lt>cpan@audreyt.orgE<gt> =head1 COPYRIGHT Copyright 2008 by Audrey Tang E<lt>cpan@audreyt.orgE<gt>. Contains derived code copyrighted 2003 by Joe Schaefer, E<lt>joe+cpan@sunstarsys.comE<gt>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut PK ! G��G� � FakeDiffOp.phpnu �Iw�� <?php namespace Wikimedia\Tests\Diff; use Wikimedia\Diff\DiffOp; /** * Class FakeDiffOp used to test abstract class DiffOp */ class FakeDiffOp extends DiffOp { public function reverse() { return null; } } PK ! Q �, , ArrayDiffFormatterTest.phpnu �Iw�� <?php namespace Wikimedia\Tests\Diff; use MediaWikiUnitTestCase; use Wikimedia\Diff\ArrayDiffFormatter; use Wikimedia\Diff\Diff; use Wikimedia\Diff\DiffOp; /** * @author Addshore * * @group Diff */ class ArrayDiffFormatterTest extends MediaWikiUnitTestCase { /** * @param Diff $input * @param array $expectedOutput * @dataProvider provideTestFormat * @covers \Wikimedia\Diff\ArrayDiffFormatter::format */ public function testFormat( Diff $input, array $expectedOutput ) { $instance = new ArrayDiffFormatter(); $output = $instance->format( $input ); $this->assertSame( $expectedOutput, $output ); } private function getMockDiff( array $edits ) { $diff = $this->createMock( Diff::class ); $diff->method( 'getEdits' ) ->willReturn( $edits ); return $diff; } private function getMockDiffOp( string $type, $orig = [], array $closing = [] ) { $diffOp = $this->createMock( DiffOp::class ); $diffOp->method( 'getType' ) ->willReturn( $type ); $diffOp->method( 'getOrig' ) ->willReturn( $orig ); if ( $type === 'change' ) { $diffOp->method( 'getClosing' ) ->with( $this->isType( 'integer' ) ) ->willReturn( 'mockLine' ); } else { $diffOp->method( 'getClosing' ) ->willReturn( $closing ); } return $diffOp; } public function provideTestFormat() { $emptyArrayTestCases = [ $this->getMockDiff( [] ), $this->getMockDiff( [ $this->getMockDiffOp( 'add' ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'delete' ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'change' ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'copy' ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'FOOBARBAZ' ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'add', 'line' ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'delete', [], [ 'line' ] ) ] ), $this->getMockDiff( [ $this->getMockDiffOp( 'copy', [], [ 'line' ] ) ] ), ]; foreach ( $emptyArrayTestCases as $testCase ) { yield [ $testCase, [] ]; } yield [ $this->getMockDiff( [ $this->getMockDiffOp( 'add', [], [ 'a1' ] ) ] ), [ [ 'action' => 'add', 'new' => 'a1', 'newline' => 1 ] ], ]; yield [ $this->getMockDiff( [ $this->getMockDiffOp( 'add', [], [ 'a1', 'a2' ] ) ] ), [ [ 'action' => 'add', 'new' => 'a1', 'newline' => 1 ], [ 'action' => 'add', 'new' => 'a2', 'newline' => 2 ], ], ]; yield [ $this->getMockDiff( [ $this->getMockDiffOp( 'delete', [ 'd1' ] ) ] ), [ [ 'action' => 'delete', 'old' => 'd1', 'oldline' => 1 ] ], ]; yield [ $this->getMockDiff( [ $this->getMockDiffOp( 'delete', [ 'd1', 'd2' ] ) ] ), [ [ 'action' => 'delete', 'old' => 'd1', 'oldline' => 1 ], [ 'action' => 'delete', 'old' => 'd2', 'oldline' => 2 ], ], ]; yield [ $this->getMockDiff( [ $this->getMockDiffOp( 'change', [ 'd1' ], [ 'a1' ] ) ] ), [ [ 'action' => 'change', 'old' => 'd1', 'new' => 'mockLine', 'oldline' => 1, 'newline' => 1, ] ], ]; yield [ $this->getMockDiff( [ $this->getMockDiffOp( 'change', [ 'd1', 'd2' ], [ 'a1', 'a2' ] ) ] ), [ [ 'action' => 'change', 'old' => 'd1', 'new' => 'mockLine', 'oldline' => 1, 'newline' => 1, ], [ 'action' => 'change', 'old' => 'd2', 'new' => 'mockLine', 'oldline' => 2, 'newline' => 2, ], ], ]; } } PK ! ���? ? DiffOpTest.phpnu �Iw�� <?php namespace Wikimedia\Tests\Diff; use MediaWikiUnitTestCase; /** * @author Addshore * * @group Diff */ class DiffOpTest extends MediaWikiUnitTestCase { /** * @covers \Wikimedia\Diff\DiffOp::getType */ public function testGetType() { $obj = new FakeDiffOp(); $obj->type = 'foo'; $this->assertSame( 'foo', $obj->getType() ); } /** * @covers \Wikimedia\Diff\DiffOp::getOrig */ public function testGetOrig() { $obj = new FakeDiffOp(); $obj->orig = [ 'foo' ]; $this->assertSame( [ 'foo' ], $obj->getOrig() ); } /** * @covers \Wikimedia\Diff\DiffOp::getClosing */ public function testGetClosing() { $obj = new FakeDiffOp(); $obj->closing = [ 'foo' ]; $this->assertSame( [ 'foo' ], $obj->getClosing() ); } /** * @covers \Wikimedia\Diff\DiffOp::getClosing */ public function testGetClosingWithParameter() { $obj = new FakeDiffOp(); $obj->closing = [ 'foo', 'bar', 'baz' ]; $this->assertSame( 'foo', $obj->getClosing( 0 ) ); $this->assertSame( 'bar', $obj->getClosing( 1 ) ); $this->assertSame( 'baz', $obj->getClosing( 2 ) ); $this->assertNull( $obj->getClosing( 3 ) ); } /** * @covers \Wikimedia\Diff\DiffOp::norig */ public function testNorig() { $obj = new FakeDiffOp(); $this->assertSame( 0, $obj->norig() ); $obj->orig = [ 'foo' ]; $this->assertSame( 1, $obj->norig() ); } /** * @covers \Wikimedia\Diff\DiffOp::nclosing */ public function testNclosing() { $obj = new FakeDiffOp(); $this->assertSame( 0, $obj->nclosing() ); $obj->closing = [ 'foo' ]; $this->assertSame( 1, $obj->nclosing() ); } } PK ! �I�|� � DiffTest.phpnu �Iw�� <?php namespace Wikimedia\Tests\Diff; use MediaWikiUnitTestCase; use Wikimedia\Diff\Diff; /** * @author Addshore * * @group Diff */ class DiffTest extends MediaWikiUnitTestCase { /** * @covers \Wikimedia\Diff\Diff::getEdits */ public function testGetEdits() { $obj = new Diff( [], [] ); $obj->edits = 'FooBarBaz'; $this->assertEquals( 'FooBarBaz', $obj->getEdits() ); } } PK ! )Z��� � XS.pmnu �[��� PK ! G��G� � FakeDiffOp.phpnu �Iw�� PK ! Q �, , 4 ArrayDiffFormatterTest.phpnu �Iw�� PK ! ���? ? � DiffOpTest.phpnu �Iw�� PK ! �I�|� � '# DiffTest.phpnu �Iw�� PK � �$
| ver. 1.1 | |
.
| PHP 8.4.18 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка