[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:
Jordi Boggiano 2013-05-04 20:09:58 +02:00
parent c8f95b5dab
commit f5e7f24819

View File

@ -28,12 +28,13 @@ class ServerBag extends ParameterBag
public function getHeaders()
{
$headers = array();
$contentHeaders = array('CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true);
foreach ($this->parameters as $key => $value) {
if (0 === strpos($key, 'HTTP_')) {
if ('HTTP_' === substr($key, 0, 5)) {
$headers[substr($key, 5)] = $value;
}
// CONTENT_* are not prefixed with HTTP_
elseif (in_array($key, array('CONTENT_LENGTH', 'CONTENT_MD5', 'CONTENT_TYPE'))) {
elseif (isset($contentHeaders[$key])) {
$headers[$key] = $value;
}
}