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

Skip to content

Commit 480dda4

Browse files
committed
merged branch tgabi333/master (PR #8891)
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes #8891). Discussion ---------- [DependencyInjection] optimized circular reference checker | Q | A | ------------- | --- | Bug fix? | [no] | New feature? | [no] | BC breaks? | [no] | Deprecations? | no] | Tests pass? | [yes] | Fixed tickets | [] | License | MIT | Doc PR | [] It is an addtion to my previous PR #7699 There is no need to check again previously checked sub-trees. In our tightly coupled services graph, this circular reference check runs avg 1,5ms, before that: 100ms Commits ------- 67ebf8f optimized circular reference checker
2 parents 0009deb + 96bb731 commit 480dda4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
2828
{
2929
private $currentId;
3030
private $currentPath;
31+
private $checkedNodes;
3132

3233
/**
3334
* Checks the ContainerBuilder object for circular references.
@@ -38,6 +39,7 @@ public function process(ContainerBuilder $container)
3839
{
3940
$graph = $container->getCompiler()->getServiceReferenceGraph();
4041

42+
$this->checkedNodes = array();
4143
foreach ($graph->getNodes() as $id => $node) {
4244
$this->currentId = $id;
4345
$this->currentPath = array($id);
@@ -58,15 +60,20 @@ private function checkOutEdges(array $edges)
5860
foreach ($edges as $edge) {
5961
$node = $edge->getDestNode();
6062
$id = $node->getId();
61-
$searchKey = array_search($id, $this->currentPath);
62-
$this->currentPath[] = $id;
6363

64-
if (false !== $searchKey) {
65-
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
66-
}
64+
if (empty($this->checkedNodes[$id])) {
65+
$searchKey = array_search($id, $this->currentPath);
66+
$this->currentPath[] = $id;
6767

68-
$this->checkOutEdges($node->getOutEdges());
69-
array_pop($this->currentPath);
68+
if (false !== $searchKey) {
69+
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
70+
}
71+
72+
$this->checkOutEdges($node->getOutEdges());
73+
74+
$this->checkedNodes[$id] = true;
75+
array_pop($this->currentPath);
76+
}
7077
}
7178
}
7279
}

0 commit comments

Comments
 (0)