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
This commit is contained in:
Sam Minnee 2009-08-11 06:13:33 +00:00
parent 01640b32ae
commit 70dc433d38

View File

@ -611,7 +611,9 @@ abstract class Object {
* @return array * @return array
*/ */
public function allMethodNames($custom = false) { 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])) { if($custom && isset(self::$extra_methods[$this->class])) {
return array_merge(self::$built_in_methods[$this->class], array_keys(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]; 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. * Adds any methods from {@link Extension} instances attached to this object.
@ -667,12 +661,19 @@ abstract class Object {
} }
if(method_exists($extension, 'allMethodNames')) { if(method_exists($extension, 'allMethodNames')) {
foreach($extension->allMethodNames(true) as $method) { $methodInfo = array(
self::$extra_methods[$this->class][$method] = array ( 'property' => $property,
'property' => $property, 'index' => $index,
'index' => $index, 'callSetOwnerFirst' => $extension instanceof Extension,
'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;
} }
} }
} }