From 073e73a2f4396f460c8b730038c0a526f6d7843d Mon Sep 17 00:00:00 2001 From: Silbinary Wolf Date: Mon, 4 Jan 2016 19:15:17 +1100 Subject: [PATCH] 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. --- core/ClassInfo.php | 7 +++++-- core/manifest/ClassLoader.php | 3 ++- model/Hierarchy.php | 12 ++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/ClassInfo.php b/core/ClassInfo.php index f990237b9..a4339c40f 100644 --- a/core/ClassInfo.php +++ b/core/ClassInfo.php @@ -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); } /** diff --git a/core/manifest/ClassLoader.php b/core/manifest/ClassLoader.php index cc7b8ffbf..1c43e1ea5 100644 --- a/core/manifest/ClassLoader.php +++ b/core/manifest/ClassLoader.php @@ -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); } } diff --git a/model/Hierarchy.php b/model/Hierarchy.php index 6ccc6ebc5..9a8cf67d9 100644 --- a/model/Hierarchy.php +++ b/model/Hierarchy.php @@ -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; }