Merge pull request #4979 from dhensby/pulls/3/SilbinaryWolf-minor-optimization

Replaced filterByCallback for 'Children' to just create a new array a…
This commit is contained in:
Damian Mooyman 2016-01-26 10:13:58 +13:00
commit 790a6da24e
3 changed files with 15 additions and 7 deletions

View File

@ -20,10 +20,13 @@ class ClassInfo {
}
/**
* @todo Improve documentation
* Returns true if a class or interface name exists.
*
* @param string $class
* @return bool
*/
public static function exists($class) {
return SS_ClassLoader::instance()->classExists($class);
return class_exists($class, false) || interface_exists($class, false) || SS_ClassLoader::instance()->getItemPath($class);
}
/**

View File

@ -101,7 +101,8 @@ class SS_ClassLoader {
* @return bool
*/
public function classExists($class) {
return class_exists($class, false) || interface_exists($class, false) || $this->getItemPath($class);
Deprecation::notice('4.0', 'Use ClassInfo::exists.');
return ClassInfo::exists($class);
}
}

View File

@ -493,10 +493,14 @@ class Hierarchy extends DataExtension {
public function Children() {
if(!(isset($this->_cache_children) && $this->_cache_children)) {
$result = $this->owner->stageChildren(false);
$this->_cache_children = $result->filterByCallback(function($item) {
return $item->canView();
});
}
$children = array();
foreach ($result as $record) {
if ($record->canView()) {
$children[] = $record;
}
}
$this->_cache_children = new ArrayList($children);
}
return $this->_cache_children;
}