minor #22480 [DI] Reduce memory overhead of id normalization (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Reduce memory overhead of id normalization

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

1dd3285c91 [DI] Reduce memory overhead of id normalization
This commit is contained in:
Fabien Potencier 2017-04-20 11:03:47 -06:00
commit f9bb4dccb8
18 changed files with 6 additions and 72 deletions

View File

@ -938,17 +938,16 @@ EOF;
*/
private function addNormalizedIds()
{
if (!$normalizedIds = $this->container->getNormalizedIds()) {
return '';
}
$code = " \$this->normalizedIds = array(\n";
$code = '';
$normalizedIds = $this->container->getNormalizedIds();
ksort($normalizedIds);
foreach ($normalizedIds as $id => $normalizedId) {
$code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n";
if ($this->container->has($normalizedId)) {
$code .= ' '.$this->export($id).' => '.$this->export($normalizedId).",\n";
}
}
return $code." );\n";
return $code ? " \$this->normalizedIds = array(\n".$code." );\n" : '';
}
/**

View File

@ -28,10 +28,6 @@ class Container extends AbstractContainer
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->aliases = array();
}

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->aliases = array();
}

View File

@ -29,10 +29,6 @@ class ProjectServiceContainer extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'test' => 'getTestService',
);

View File

@ -33,10 +33,6 @@ class ProjectServiceContainer extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'test' => 'getTestService',
);

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar' => 'getBarService',
);

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService',
'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService',

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'foo' => 'getFooService',
);

View File

@ -29,10 +29,6 @@ class ProjectServiceContainer extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'test' => 'getTestService',
);

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar' => 'getBarService',
'foo' => 'getFooService',

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar' => 'getBarService',
'foo' => 'getFooService',

View File

@ -28,8 +28,6 @@ class ProjectServiceContainer extends Container
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
'symfony\\component\\dependencyinjection\\tests\\fixtures\\container33\\foo' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\Container33\\Foo',
);
$this->methodMap = array(

View File

@ -29,10 +29,6 @@ class ProjectServiceContainer extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->aliases = array();
}

View File

@ -29,10 +29,6 @@ class ProjectServiceContainer extends Container
$this->parameters = $this->getDefaultParameters();
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar' => 'getBarService',
'foo' => 'getFooService',

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar_service' => 'getBarServiceService',
'baz_service' => 'getBazServiceService',

View File

@ -27,10 +27,6 @@ class ProjectServiceContainer extends Container
public function __construct()
{
$this->services = array();
$this->normalizedIds = array(
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
);
$this->methodMap = array(
'bar_service' => 'getBarServiceService',
'baz_service' => 'getBazServiceService',

View File

@ -29,9 +29,6 @@ class ProjectServiceContainer extends Container
$this->services = array();
$this->normalizedIds = array(
'autowired.symfony\\component\\dependencyinjection\\tests\\fixtures\\customdefinition' => 'autowired.Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
'psr\\container\\containerinterface' => 'Psr\\Container\\ContainerInterface',
'symfony\\component\\dependencyinjection\\containerinterface' => 'Symfony\\Component\\DependencyInjection\\ContainerInterface',
'symfony\\component\\dependencyinjection\\tests\\fixtures\\customdefinition' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition',
'symfony\\component\\dependencyinjection\\tests\\fixtures\\testservicesubscriber' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\TestServiceSubscriber',
);
$this->methodMap = array(