From 79ff1f10d2d6553d0a73203c8267e1acd9e8d98c Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Mon, 28 May 2012 12:20:35 -0400 Subject: [PATCH] Optimized getParameter. --- lib/Doctrine/ORM/AbstractQuery.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index f402c743a..b0c07e129 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -166,14 +166,15 @@ abstract class AbstractQuery */ public function getParameter($key) { - foreach ($this->parameters->getIterator() as $parameter) { - // Must not be identical because of string to integer conversion - if ($parameter->getName() == $key) { - return $parameter; + $filteredParameters = $this->parameters->filter( + function ($parameter) use ($key) + { + // Must not be identical because of string to integer conversion + return ($key == $parameter->getName()); } - } + ); - return null; + return count($filteredParameters) ? $filteredParameters->first() : null; } /**