merged branch Seldaek/optim (PR #7931)

This PR was merged into the master branch.

Discussion
----------

A few optimizations

Commits
-------

ea633f5 [HttpKernel] Avoid updating the context if the request did not change
997d549 [HttpFoundation] Avoid a few unnecessary str_replace() calls
f5e7f24 [HttpFoundation] Optimize ServerBag::getHeaders()
This commit is contained in:
Fabien Potencier 2013-05-06 08:18:48 +02:00
commit c8525862f5
3 changed files with 10 additions and 11 deletions

View File

@ -136,20 +136,16 @@ class RequestMatcher implements RequestMatcherInterface
}
foreach ($this->attributes as $key => $pattern) {
if (!preg_match('#'.str_replace('#', '\\#', $pattern).'#', $request->attributes->get($key))) {
if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
return false;
}
}
if (null !== $this->path) {
$path = str_replace('#', '\\#', $this->path);
if (!preg_match('#'.$path.'#', rawurldecode($request->getPathInfo()))) {
return false;
}
if (null !== $this->path && !preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
return false;
}
if (null !== $this->host && !preg_match('#'.str_replace('#', '\\#', $this->host).'#i', $request->getHost())) {
if (null !== $this->host && !preg_match('{'.$this->host.'}i', $request->getHost())) {
return false;
}

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;
}
}

View File

@ -35,6 +35,7 @@ class RouterListener implements EventSubscriberInterface
private $matcher;
private $context;
private $logger;
private $request;
/**
* Constructor.
@ -72,9 +73,10 @@ class RouterListener implements EventSubscriberInterface
*/
public function setRequest(Request $request = null)
{
if (null !== $request) {
if (null !== $request && $this->request !== $request) {
$this->context->fromRequest($request);
}
$this->request = $request;
}
public function onKernelRequest(GetResponseEvent $event)