Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1aa4798

Browse files
committed
Improve performance
1 parent b9b81fe commit 1aa4798

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class PhpDumper extends Dumper
5858
private $targetDirRegex;
5959
private $targetDirMaxMatches;
6060
private $docStar;
61-
private $existingNames = array();
61+
private $serviceIdToMethodNameMap = array();
62+
private $usedMethodNames = array();
6263

6364
/**
6465
* @var \Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface
@@ -1350,19 +1351,20 @@ private function getServiceCall($id, Reference $reference = null)
13501351
*/
13511352
private function camelize($id)
13521353
{
1353-
if (isset($this->existingNames[$id])) {
1354-
return $this->existingNames[$id];
1354+
if (isset($this->serviceIdToMethodNameMap[$id])) {
1355+
return $this->serviceIdToMethodNameMap[$id];
13551356
}
13561357

13571358
$name = Container::camelize($id);
13581359
$uniqueName = $name = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', $name);
1359-
$prefix = 1;
1360+
$suffix = 1;
13601361

1361-
while (in_array($uniqueName, $this->existingNames)) {
1362-
++$prefix;
1363-
$uniqueName = $name.$prefix;
1362+
while (isset($this->usedMethodNames[$uniqueName])) {
1363+
++$suffix;
1364+
$uniqueName = $name.$suffix;
13641365
}
1365-
$this->existingNames[$id] = $uniqueName;
1366+
$this->serviceIdToMethodNameMap[$id] = $uniqueName;
1367+
$this->usedMethodNames[$uniqueName] = true;
13661368

13671369
return $uniqueName;
13681370
}

0 commit comments

Comments
 (0)