[HttpFoundation] Optimize ServerBag::getHeaders()
isset() vs in_array makes it take half the time (1ms/req here) substr() does not have to scan the whole string so it's a wee bit faster
This commit is contained in:
parent
c8f95b5dab
commit
f5e7f24819
@ -28,12 +28,13 @@ class ServerBag extends ParameterBag
|
|||||||
public function getHeaders()
|
public function getHeaders()
|
||||||
{
|
{
|
||||||
$headers = array();
|
$headers = array();
|
||||||
|
$contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
|
||||||
foreach ($this->parameters as $key => $value) {
|
foreach ($this->parameters as $key => $value) {
|
||||||
if (0 === strpos($key, 'HTTP_')) {
|
if ('HTTP_' === substr($key, 0, 5)) {
|
||||||
$headers[substr($key, 5)] = $value;
|
$headers[substr($key, 5)] = $value;
|
||||||
}
|
}
|
||||||
// CONTENT_* are not prefixed with HTTP_
|
// CONTENT_* are not prefixed with HTTP_
|
||||||
elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
|
elseif (isset($contentHeaders[$key])) {
|
||||||
$headers[$key] = $value;
|
$headers[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user