Skip to content

Commit e796d8d

Browse files
committed
Fixed SequenceMatcher::getMatchingBlocks
1 parent 3dae6fb commit e796d8d

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# [2.0.3](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.3) (2016-07-18)
22

3-
* Fixed BaseArray class name
3+
* Fixed `BaseArray` class name
4+
* Fixed `SequenceMatcher::getMatchingBlocks`
45

56
# [2.0.2](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.2) (2016-07-18)
67

7-
* Fixed Renderer namespace
8+
* Fixed `Renderer` namespace
89

910
# [2.0.1](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.1) (2016-07-18)
1011

1112
* Fixed Composer autoload namespace
12-
* Adding a CONTRIBUTING file
13+
* Adding a `CONTRIBUTING.md` file
1314

1415
# [2.0.0](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.0) (2016-07-17)
1516

src/Diff/SequenceMatcher.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function setOptions(array $options)
113113
public function setSequences($a, $b)
114114
{
115115
$this->setSeq1($a)
116-
->setSeq2($b);
116+
->setSeq2($b);
117117

118118
return $this;
119119
}
@@ -284,31 +284,31 @@ public function findLongestMatch($alo, $ahi, $blo, $bhi)
284284
while ($bestI > $alo && $bestJ > $blo && !$this->isBJunk($b[$bestJ - 1]) &&
285285
!$this->linesAreDifferent($bestI - 1, $bestJ - 1)
286286
) {
287-
--$bestI;
288-
--$bestJ;
289-
++$bestSize;
287+
--$bestI;
288+
--$bestJ;
289+
++$bestSize;
290290
}
291291

292292
while ($bestI + $bestSize < $ahi &&
293293
($bestJ + $bestSize) < $bhi &&
294294
!$this->isBJunk($b[$bestJ + $bestSize]) &&
295295
!$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)
296296
) {
297-
++$bestSize;
297+
++$bestSize;
298298
}
299299

300300
while ($bestI > $alo && $bestJ > $blo && $this->isBJunk($b[$bestJ - 1]) &&
301-
!$this->linesAreDifferent($bestI - 1, $bestJ - 1)) {
302-
--$bestI;
303-
--$bestJ;
304-
++$bestSize;
301+
!$this->linesAreDifferent($bestI - 1, $bestJ - 1)) {
302+
--$bestI;
303+
--$bestJ;
304+
++$bestSize;
305305
}
306306

307307
while ($bestI + $bestSize < $ahi &&
308308
$bestJ + $bestSize < $bhi && $this->isBJunk($b[$bestJ + $bestSize]) &&
309309
!$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)
310310
) {
311-
++$bestSize;
311+
++$bestSize;
312312
}
313313

314314
return [
@@ -367,16 +367,9 @@ public function getMatchingBlocks()
367367
$aLength = count($this->a);
368368
$bLength = count($this->b);
369369

370-
$queue = [
371-
[
372-
0,
373-
$aLength,
374-
0,
375-
$bLength
376-
]
377-
];
378-
370+
$queue = [[0, $aLength, 0, $bLength]];
379371
$matchingBlocks = [];
372+
380373
while (!empty($queue)) {
381374
list ($alo, $ahi, $blo, $bhi) = array_pop($queue);
382375
$x = $this->findLongestMatch($alo, $ahi, $blo, $bhi);
@@ -408,7 +401,8 @@ public function getMatchingBlocks()
408401
$i1 = 0;
409402
$j1 = 0;
410403
$k1 = 0;
411-
$nonAdjacent = [$this, 'tupleSort'];
404+
$nonAdjacent = [];
405+
412406
foreach ($matchingBlocks as $block) {
413407
list ($i2, $j2, $k2) = $block;
414408

0 commit comments

Comments
 (0)