From ea633f57870cef9df2849c0c23a42fe49f0357c9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 4 May 2013 20:51:13 +0200 Subject: [PATCH] [HttpKernel] Avoid updating the context if the request did not change Due to the BC $this->setRequest() call in the onKernelRequest method, the request is set twice every time in Symfony, and RequestContext::fromRequest takes 1ms to run here so if we can skip one call it is a win. --- .../Component/HttpKernel/EventListener/RouterListener.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php index 58ea6f0a5436..f68716c144f8 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php @@ -35,6 +35,7 @@ class RouterListener implements EventSubscriberInterface private $matcher; private $context; private $logger; + private $request; /** * Constructor. @@ -72,9 +73,10 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte */ 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)