Skip to content

Commit

Permalink
Perf optimize StringUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 29, 2024
1 parent 2184b7a commit 191fc8d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
namespace SebastianBergmann\Comparator;

use function str_replace;
use function strlen;
use function substr;

Expand All @@ -31,8 +30,8 @@ public static function removeOverlongCommonPrefix(string $string1, string $strin
$commonPrefix = self::findCommonPrefix($string1, $string2);

if (strlen($commonPrefix) > self::OVERLONG_PREFIX_THRESHOLD) {
$string1 = str_replace(substr($commonPrefix, 0, -self::KEEP_PREFIX_CHARS), '...', $string1);
$string2 = str_replace(substr($commonPrefix, 0, -self::KEEP_PREFIX_CHARS), '...', $string2);
$string1 = '...' . substr($string1, strlen($commonPrefix) - self::KEEP_PREFIX_CHARS);
$string2 = '...' . substr($string2, strlen($commonPrefix) - self::KEEP_PREFIX_CHARS);
}

return [$string1, $string2];
Expand Down

0 comments on commit 191fc8d

Please sign in to comment.