ENHANCEMENT: Improved performance of ViewableData casting by removing an object::get_static call

From: Sam Minnee <sam@silverstripe.com>

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88570 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-10-12 00:40:15 +00:00
parent b59d12e16e
commit b868075ef3

View File

@ -35,13 +35,6 @@ class ViewableData extends Object implements IteratorAggregate {
*/
public static $default_cast = 'HTMLVarchar';
/**
* An array of static property names to search for properties to get casting information from.
*
* @var array
*/
public static $casting_properties = array('casting');
/**
* @var array
*/
@ -314,7 +307,11 @@ class ViewableData extends Object implements IteratorAggregate {
foreach($ancestry as $class) {
if(!isset(self::$casting_cache[$class]) && $merge) {
if($class) $mergeFields = Object::get_static($class, 'casting_properties');
if($class instanceof DataObject) {
$mergeFields = array('db', 'casting');
} else {
$mergeFields = array('casting');
}
if($mergeFields) foreach($mergeFields as $field) {
$casting = Object::uninherited_static($class, $field);
@ -329,7 +326,7 @@ class ViewableData extends Object implements IteratorAggregate {
$cache = ($cache) ? array_merge(self::$casting_cache[$class], $cache) : self::$casting_cache[$class];
}
if($class == 'ViewableData') $merge = false;
if($class == 'ViewableData') break;
}
}
@ -383,9 +380,9 @@ class ViewableData extends Object implements IteratorAggregate {
if(!$cacheName) $cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName;
if(!isset($this->objCache[$cacheName]) || !$cache) {
if(!isset($this->objCache[$cacheName])) {
if($this->hasMethod($fieldName)) {
$value = call_user_func_array(array($this, $fieldName), (is_array($arguments) ? $arguments : array()));
$value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->$fieldName();
} else {
$value = $this->$fieldName;
}