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 https://github.com/symfony/symfony/pull/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
This commit is contained in:
commit
480dda41cf
@ -28,6 +28,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
{
|
||||
private $currentId;
|
||||
private $currentPath;
|
||||
private $checkedNodes;
|
||||
|
||||
/**
|
||||
* Checks the ContainerBuilder object for circular references.
|
||||
@ -38,6 +39,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
{
|
||||
$graph = $container->getCompiler()->getServiceReferenceGraph();
|
||||
|
||||
$this->checkedNodes = array();
|
||||
foreach ($graph->getNodes() as $id => $node) {
|
||||
$this->currentId = $id;
|
||||
$this->currentPath = array($id);
|
||||
@ -58,15 +60,20 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
foreach ($edges as $edge) {
|
||||
$node = $edge->getDestNode();
|
||||
$id = $node->getId();
|
||||
$searchKey = array_search($id, $this->currentPath);
|
||||
$this->currentPath[] = $id;
|
||||
|
||||
if (false !== $searchKey) {
|
||||
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
|
||||
if (empty($this->checkedNodes[$id])) {
|
||||
$searchKey = array_search($id, $this->currentPath);
|
||||
$this->currentPath[] = $id;
|
||||
|
||||
if (false !== $searchKey) {
|
||||
throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey));
|
||||
}
|
||||
|
||||
$this->checkOutEdges($node->getOutEdges());
|
||||
|
||||
$this->checkedNodes[$id] = true;
|
||||
array_pop($this->currentPath);
|
||||
}
|
||||
|
||||
$this->checkOutEdges($node->getOutEdges());
|
||||
array_pop($this->currentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user