Skip to content

remove unused junk function && callback function #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
remove unused junk function && callback function
Fix #40
  • Loading branch information
JBlond committed Jul 9, 2020
commit 7b4beedbe513cfa62964269889bf77bb0214c95a
53 changes: 1 addition & 52 deletions lib/jblond/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
*/
class SequenceMatcher
{
/**
* @var string|array Either a string or an array containing a callback function to determine
* if a line is "junk" or not.
*/
private $junkCallback;

/**
* @var array The first sequence to compare against.
Expand All @@ -38,11 +33,6 @@ class SequenceMatcher
*/
private $new;

/**
* @var array Array of characters that are considered junk from the second sequence. Characters are the array key.
*/
private $junkDict = [];

/**
* @var array Array of indices that do not contain junk elements.
*/
Expand Down Expand Up @@ -82,14 +72,11 @@ class SequenceMatcher
* @param string|array $old A string or array containing the lines to compare against.
* @param string|array $new A string or array containing the lines to compare.
* @param array $options
* @param string|array|null $junkCallback Either an array or string that references a callback function
* (if there is one) to determine 'junk' characters.
*/
public function __construct($old, $new, array $options = [], $junkCallback = null)
public function __construct($old, $new, array $options = [])
{
$this->old = [];
$this->new = [];
$this->junkCallback = $junkCallback;
$this->setOptions($options);
$this->setSequences($old, $new);
}
Expand Down Expand Up @@ -188,39 +175,6 @@ private function chainB()
foreach (array_keys($popularDict) as $char) {
unset($this->b2j[$char]);
}

$this->junkDict = [];
if (is_callable($this->junkCallback)) {
foreach (array_keys($popularDict) as $char) {
if (call_user_func($this->junkCallback, $char)) {
$this->junkDict[$char] = 1;
unset($popularDict[$char]);
}
}

foreach (array_keys($this->b2j) as $char) {
if (call_user_func($this->junkCallback, $char)) {
$this->junkDict[$char] = 1;
unset($this->b2j[$char]);
}
}
}
}

/**
* Checks if a particular character is in the junk dictionary
* for the list of junk characters.
*
* @param string $bString
* @return bool $b True if the character is considered junk. False if not.
*/
private function isBJunk(string $bString): bool
{
if (isset($this->junkDict[$bString])) {
return true;
}

return false;
}

/**
Expand All @@ -246,7 +200,6 @@ private function isBJunk(string $bString): bool
public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
{
$old = $this->old;
$new = $this->new;

$bestI = $alo;
$bestJ = $blo;
Expand Down Expand Up @@ -280,7 +233,6 @@ public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
while (
$bestI > $alo &&
$bestJ > $blo &&
!$this->isBJunk($new[$bestJ - 1]) &&
!$this->linesAreDifferent($bestI - 1, $bestJ - 1)
) {
--$bestI;
Expand All @@ -291,7 +243,6 @@ public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
while (
$bestI + $bestSize < $ahi &&
($bestJ + $bestSize) < $bhi &&
!$this->isBJunk($new[$bestJ + $bestSize]) &&
!$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)
) {
++$bestSize;
Expand All @@ -300,7 +251,6 @@ public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
while (
$bestI > $alo &&
$bestJ > $blo &&
$this->isBJunk($new[$bestJ - 1]) &&
!$this->linesAreDifferent($bestI - 1, $bestJ - 1)
) {
--$bestI;
Expand All @@ -311,7 +261,6 @@ public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi): array
while (
$bestI + $bestSize < $ahi &&
$bestJ + $bestSize < $bhi &&
$this->isBJunk($new[$bestJ + $bestSize]) &&
!$this->linesAreDifferent($bestI + $bestSize, $bestJ + $bestSize)
) {
++$bestSize;
Expand Down