From 037d7425fee007af6edb43affbd8e9ed9c5f32d1 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 6 Aug 2011 15:18:04 -0400 Subject: [PATCH] More optimizations by caching the value of IsRequired() --- base/weak_interface.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/base/weak_interface.php b/base/weak_interface.php index 7d16b08..5f73f9d 100644 --- a/base/weak_interface.php +++ b/base/weak_interface.php @@ -121,11 +121,15 @@ class MethodImp /*! @var ReflectionMethod The method of the actual interface that this is implementing. */ private $method = NULL; + /*! @var bool Whether or not this is required. */ + private $required = FALSE; + public function __construct(\hoplite\base\WeakInterface $interface, \ReflectionMethod $method) { $this->interface = $interface; $this->method = $method; + $this->required = strpos($this->method->GetDocComment(), '@required') !== FALSE; } /*! Forwards a method call. */ @@ -134,7 +138,7 @@ class MethodImp try { $impl = $reflector->GetMethod($this->method->name); } catch (\ReflectionException $e) { - if ($this->IsRequired()) + if ($this->required) throw $e; return; } @@ -150,7 +154,7 @@ class MethodImp /*! Checks if a method is marked as required. */ public function IsRequired() { - return strpos($this->method->GetDocComment(), '@required') !== FALSE; + return $this->required; } } -- 2.22.5