Skip to content
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

Micro-optimize NamePrettifier::prettifyTestMethodName() once again #5750

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Logging/TestDox/NamePrettifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use function method_exists;
use function preg_quote;
use function preg_replace;
use function range;
use function rtrim;
use function sprintf;
use function str_contains;
use function str_ends_with;
Expand Down Expand Up @@ -114,11 +114,11 @@ public function prettifyTestMethodName(string $name): string
return '';
}

$string = (string) preg_replace('#\d+$#', '', $name, -1, $count);
$string = rtrim($name, '0123456789');

if (array_key_exists($string, self::$strings)) {
$name = $string;
} elseif ($count === 0) {
} elseif ($string === $name) {
self::$strings[$string] = 1;
}

Expand All @@ -144,7 +144,9 @@ public function prettifyTestMethodName(string $name): string

$buffer = '';

foreach (range(0, strlen($name) - 1) as $i) {
$len = strlen($name);

for ($i = 0; $i < $len; $i++) {
if ($i > 0 && $name[$i] >= 'A' && $name[$i] <= 'Z') {
$buffer .= ' ' . strtolower($name[$i]);
} else {
Expand Down