mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
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:
parent
e091bb8474
commit
073e73a2f4
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user