From 70dc433d38df87a3e5d92f0851d592f1e26c7b84 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 11 Aug 2009 06:13:33 +0000 Subject: [PATCH] ENHANCEMENT: Improved performance of Object::allMethodNames() and Object::addMethodsFrom() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84158 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/Object.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/core/Object.php b/core/Object.php index d13ccc7ae..97bca7c9d 100755 --- a/core/Object.php +++ b/core/Object.php @@ -611,7 +611,9 @@ abstract class Object { * @return array */ public function allMethodNames($custom = false) { - if(!isset(self::$built_in_methods['_set'][$this->class])) $this->buildMethodList(); + if(!isset(self::$built_in_methods[$this->class])) { + self::$built_in_methods[$this->class] = array_map('strtolower', get_class_methods($this)); + } if($custom && isset(self::$extra_methods[$this->class])) { return array_merge(self::$built_in_methods[$this->class], array_keys(self::$extra_methods[$this->class])); @@ -619,14 +621,6 @@ abstract class Object { return self::$built_in_methods[$this->class]; } } - - protected function buildMethodList() { - foreach(get_class_methods($this) as $method) { - self::$built_in_methods[$this->class][strtolower($method)] = strtolower($method); - } - - self::$built_in_methods['_set'][$this->class] = true; - } /** * Adds any methods from {@link Extension} instances attached to this object. @@ -667,12 +661,19 @@ abstract class Object { } if(method_exists($extension, 'allMethodNames')) { - foreach($extension->allMethodNames(true) as $method) { - self::$extra_methods[$this->class][$method] = array ( - 'property' => $property, - 'index' => $index, - 'callSetOwnerFirst' => $extension instanceof Extension, - ); + $methodInfo = array( + 'property' => $property, + 'index' => $index, + 'callSetOwnerFirst' => $extension instanceof Extension, + ); + + $newMethods = array_fill_keys($extension->allMethodNames(true), $methodInfo); + + if(isset(self::$extra_methods[$this->class])) { + self::$extra_methods[$this->class] = + array_merge(self::$extra_methods[$this->class], $newMethods); + } else { + self::$extra_methods[$this->class] = $newMethods; } } }