Skip to content

Commit

Permalink
minor #22480 [DI] Reduce memory overhead of id normalization (nicolas…
Browse files Browse the repository at this point in the history
…-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
-------

1dd3285 [DI] Reduce memory overhead of id normalization
  • Loading branch information
fabpot committed Apr 20, 2017
2 parents 589d9aa + 1dd3285 commit f9bb4dc
Show file tree
Hide file tree
Showing 18 changed files with 6 additions and 72 deletions.
13 changes: 6 additions & 7 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -938,17 +938,16 @@ public function isFrozen()
*/
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" : '';
}

/**
Expand Down
Expand Up @@ -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();
}
Expand Down
Expand Up @@ -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();
}
Expand Down
Expand Up @@ -29,10 +29,6 @@ public function __construct()
$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',
);
Expand Down
Expand Up @@ -33,10 +33,6 @@ public function __construct()
$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',
);
Expand Down
Expand Up @@ -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',
);
Expand Down
Expand Up @@ -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',
Expand Down
Expand Up @@ -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',
);
Expand Down
Expand Up @@ -29,10 +29,6 @@ public function __construct()
$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',
);
Expand Down
Expand Up @@ -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',
Expand Down
Expand Up @@ -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',
Expand Down
Expand Up @@ -28,8 +28,6 @@ public function __construct()
{
$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(
Expand Down
Expand Up @@ -29,10 +29,6 @@ public function __construct()
$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();
}
Expand Down
Expand Up @@ -29,10 +29,6 @@ public function __construct()
$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',
Expand Down
Expand Up @@ -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',
Expand Down
Expand Up @@ -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',
Expand Down
Expand Up @@ -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',
Expand Down
Expand Up @@ -29,9 +29,6 @@ public function __construct()
$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(
Expand Down

0 comments on commit f9bb4dc

Please sign in to comment.