Skip to content

Commit

Permalink
Improved removeFullyOverlappingStrings() performance by adding a leng…
Browse files Browse the repository at this point in the history
…th check
  • Loading branch information
JoshyPHP committed Dec 22, 2016
1 parent dae48da commit f3e57ac
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ShortestCommonSuperstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ protected function removeEmptyStrings()
*/
protected function removeFullyOverlappingStrings()
{
$i = count($this->strings);
$strlen = array_map('strlen', $this->strings);
$i = count($this->strings);
while (--$i > 0)
{
$str = $this->strings[$i];
$j = $i;
$len = $strlen[$i];
$j = $i;
while (--$j >= 0)
{
if (strpos($this->strings[$j], $str) !== false)
if ($strlen[$j] > $len && strpos($this->strings[$j], $str) !== false)
{
unset($this->strings[$i]);
break;
Expand Down

0 comments on commit f3e57ac

Please sign in to comment.