Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Commit

Permalink
optimized path compare utility
Browse files Browse the repository at this point in the history
  • Loading branch information
breadlesscode committed Jan 10, 2018
1 parent 9720efb commit 21d53a4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Classes/Utility/PathUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ public static function path2array($path, $delimiter = '/')
public static function compare($pathOne, $pathTwo, $delimiter = '/')
{
$pathOne = self::path2array($pathOne);
$pathTwo = self::path2array($pathTwo);

for ($distance = 0; $distance < count($pathOne); $distance++) {
for ($p2index = 0; $p2index < count($pathTwo); $p2index++) {
if ($pathOne[$distance] === $pathTwo[$p2index]) {
return $distance + $p2index;
}
if ($pathOne[$distance] === $pathTwo) {
return $distance;
}
}

return -1;
return null;
}
}

0 comments on commit 21d53a4

Please sign in to comment.