Skip to content

Commit 8cd2193

Browse files
minor symfony#24866 Micro optim using explicit root namespaces (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- Micro optim using explicit root namespaces | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Just doing that makes my local hello world as fast on 3.3 as on 4.0. Spotted using Blackfire to identify the hot path. Confirmed using both `ab` and `blackfire curl` on a local `php -S`. It's not the first time these root namespaces make a measurable difference (on a selected list of functions only, see PHP-CS-Fixer/PHP-CS-Fixer#3048.) PHP-CS-Fixer/PHP-CS-Fixer#3222 might become a more generic fix for this kind of optims. Commits ------- e78d1c4 Micro optim using explicit root namespaces
2 parents 850bb2d + e78d1c4 commit 8cd2193

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/Symfony/Component/EventDispatcher/EventDispatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected function doDispatch($listeners, $eventName, Event $event)
209209
if ($event->isPropagationStopped()) {
210210
break;
211211
}
212-
call_user_func($listener, $event, $eventName, $this);
212+
\call_user_func($listener, $event, $eventName, $this);
213213
}
214214
}
215215

@@ -225,7 +225,7 @@ private function sortListeners($eventName)
225225

226226
foreach ($this->listeners[$eventName] as $priority => $listeners) {
227227
foreach ($listeners as $k => $listener) {
228-
if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
228+
if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
229229
$listener[0] = $listener[0]();
230230
$this->listeners[$eventName][$priority][$k] = $listener;
231231
}

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function get($key, $default = null, $first = true)
121121
}
122122

123123
if ($first) {
124-
return count($headers[$key]) ? $headers[$key][0] : $default;
124+
return \count($headers[$key]) ? $headers[$key][0] : $default;
125125
}
126126

127127
return $headers[$key];
@@ -138,12 +138,20 @@ public function set($key, $values, $replace = true)
138138
{
139139
$key = str_replace('_', '-', strtolower($key));
140140

141-
$values = array_values((array) $values);
141+
if (\is_array($values)) {
142+
$values = array_values($values);
142143

143-
if (true === $replace || !isset($this->headers[$key])) {
144-
$this->headers[$key] = $values;
144+
if (true === $replace || !isset($this->headers[$key])) {
145+
$this->headers[$key] = $values;
146+
} else {
147+
$this->headers[$key] = array_merge($this->headers[$key], $values);
148+
}
145149
} else {
146-
$this->headers[$key] = array_merge($this->headers[$key], $values);
150+
if (true === $replace || !isset($this->headers[$key])) {
151+
$this->headers[$key] = array($values);
152+
} else {
153+
$this->headers[$key][] = $values;
154+
}
147155
}
148156

149157
if ('cache-control' === $key) {

src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function set($key, $values, $replace = true)
122122
parent::set($key, $values, $replace);
123123

124124
// ensure the cache-control header has sensible defaults
125-
if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) {
125+
if (\in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'), true)) {
126126
$computed = $this->computeCacheControlValue();
127127
$this->headers['cache-control'] = array($computed);
128128
$this->headerNames['cache-control'] = 'Cache-Control';

0 commit comments

Comments
 (0)