Replaced filterByCallback for 'Children' to just create a new array as function calls are exponentially expensive in PHP (the more functions that exist, the slower a function call becomes) and replaced 'array_key_exists' with op-code equivalent for speed. The best increase isn't really noticeable but we should work towards optimizing the core as much as possible.

This commit is contained in:
Silbinary Wolf 2016-01-04 19:15:17 +11:00 committed by Daniel Hensby
parent e091bb8474
commit 073e73a2f4
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;
}