8000 [DependencyInjection] Optimize exporting variables · symfony/symfony@768de2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 768de2f

Browse files
Sander van der Vlugtnicolas-grekas
Sander van der Vlugt
authored andcommitted
[DependencyInjection] Optimize exporting variables
1 parent 261c0de commit 768de2f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PhpDumper extends Dumper
8080
private $addGetService = false;
8181
private $locatedIds = array();
8282
private $serviceLocatorTag;
83+
private $exportedVariables = array();
8384

8485
/**
8586
* @var ProxyDumper
@@ -125,6 +126,7 @@ public function dump(array $options = array())
125126
$this->locatedIds = array();
126127
$this->targetDirRegex = null;
127128
$this->inlinedRequires = array();
129+
$this->exportedVariables = array();
128130
$options = array_merge(array(
129131
'class' => 'ProjectServiceContainer',
130132
'base_class' => 'Container',
@@ -304,6 +306,7 @@ public function dump(array $options = array())
304306
$this->inlinedRequires = array();
305307
$this->circularReferences = array();
306308
$this->locatedIds = array();
309+
$this->exportedVariables = array();
307310

308311
$unusedEnvs = array();
309312
foreach ($this->container->getEnvCounters() as $env => $use) {
@@ -1768,6 +1771,10 @@ private function export($value)
17681771

17691772
private function doExport($value, $resolveEnv = false)
17701773
{
1774+
$shouldCacheValue = $resolveEnv && \is_string($value);
1775+
if ($shouldCacheValue && isset($this->exportedVariables[$value])) {
1776+
return $this->exportedVariables[$value];
1777+
}
17711778
if (\is_string($value) && false !== strpos($value, "\n")) {
17721779
$cleanParts = explode("\n", $value);
17731780
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
@@ -1789,6 +1796,10 @@ private function doExport($value, $resolveEnv = false)
17891796
}
17901797
}
17911798

1799+
if ($shouldCacheValue) {
1800+
$this->exportedVariables[$value] = $export;
1801+
}
1802+
17921803
return $export;
17931804
}
17941805
}

0 commit comments

Comments
 (0)
0