From 661a6c80d86fa61d185f956547dc57dc2460c3a6 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 6 Aug 2011 15:17:26 -0400 Subject: [PATCH] Speed up WeakInterface by 2x by caching the object reflector. --- base/weak_interface.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/base/weak_interface.php b/base/weak_interface.php index 1f644a4..7d16b08 100644 --- a/base/weak_interface.php +++ b/base/weak_interface.php @@ -34,6 +34,9 @@ class WeakInterface /*! @var object The object to which this interface is bound. */ private $object = NULL; + /*! @var ReflectionClass The reflector of #object. */ + private $object_reflector = NULL; + /*! @var bool Whether or not a NULL object will throw when called. */ private $null_allowed = FALSE; @@ -65,6 +68,7 @@ class WeakInterface { $this->_CheckObject($object); $this->object = $object; + $this->object_reflector = new \ReflectionClass($this->object); } /*! Magic method that performs the actual method invocation. */ @@ -77,7 +81,7 @@ class WeakInterface return; } - return $this->imps[$meth]->Invoke($args); + return $this->imps[$meth]->Invoke($this->object_reflector, $args); } /*! Ensures that the bound object properly implements the interface. */ @@ -125,9 +129,8 @@ class MethodImp } /*! Forwards a method call. */ - public function Invoke($args) + public function Invoke($reflector, $args) { - $reflector = new \ReflectionClass($this->interface->get()); try { $impl = $reflector->GetMethod($this->method->name); } catch (\ReflectionException $e) { -- 2.22.5