More optimizations by caching the value of IsRequired()
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 6 Aug 2011 19:18:04 +0000 (15:18 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 6 Aug 2011 19:18:10 +0000 (15:18 -0400)
base/weak_interface.php

index 7d16b08fd7de4b6e9dab2db1e92686b331f56328..5f73f9da8f2fb5c684b2ec1a0817a067346b6276 100644 (file)
@@ -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;
   }
 }