From b868075ef398d57fa44bd1ac665b975b2556b2fa Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 12 Oct 2009 00:40:15 +0000 Subject: [PATCH] ENHANCEMENT: Improved performance of ViewableData casting by removing an object::get_static call From: Sam Minnee git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88570 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ViewableData.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/core/ViewableData.php b/core/ViewableData.php index 2314c0692..655dc7cc0 100755 --- a/core/ViewableData.php +++ b/core/ViewableData.php @@ -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; }