8000 minor #40419 [Console] Avoid unneeded preg_replace_callback (bnf) · symfony/symfony@6dd2d7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 6dd2d7b

Browse files
committed
minor #40419 [Console] Avoid unneeded preg_replace_callback (bnf)
This PR was merged into the 5.3-dev branch. Discussion ---------- [Console] Avoid unneeded preg_replace_callback | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | no | License | MIT Motivations for this change: * Avoid an unneded preg call, explode+implode is faster * The previous regex created to suboptimal expressions, due to the pipe that caused empty to be matched. That means an input like `foo:bar` was translated into `foo[^:]*[^:]*:bar[^:]*[^:]*` instead of simply `foo[^:]*:bar[^:]*` Commits ------- daaa760 Avoid unneeded preg_replace_callback in console application
2 parents 10d869d + daaa760 commit 6dd2d7b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ public function getNamespaces()
589589
public function findNamespace(string $namespace)
590590
{
591591
$allNamespaces = $this->getNamespaces();
592-
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
592+
$expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
593593
$namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
594594

595595
if (empty($namespaces)) {
@@ -645,7 +645,7 @@ public function find(string $name)
645645
}
646646

647647
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
648-
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
648+
$expr = implode('[^:]*:', array_map('preg_quote', explode(':', $name))).'[^:]*';
649649
$commands = preg_grep('{^'.$expr.'}', $allCommands);
650650

651651
if (empty($commands)) {

0 commit comments

Comments
 (0)
0