Merge pull request #7133 from kinglozzer/cache-classname

Cache ClassInfo::class_name() calls
This commit is contained in:
Daniel Hensby 2017-07-10 13:23:45 +01:00 committed by GitHub
commit b2831b809c

View File

@ -64,6 +64,14 @@ class ClassInfo
*/ */
private static $_cache_parse = []; private static $_cache_parse = [];
/**
* Cache for class_name
*
* @internal
* @var array
*/
private static $_cache_class_names = [];
/** /**
* @todo Move this to SS_Database or DB * @todo Move this to SS_Database or DB
* *
@ -200,8 +208,14 @@ class ClassInfo
if (is_object($nameOrObject)) { if (is_object($nameOrObject)) {
return get_class($nameOrObject); return get_class($nameOrObject);
} }
$reflection = new ReflectionClass($nameOrObject);
return $reflection->getName(); $key = strtolower($nameOrObject);
if (!isset(static::$_cache_class_names[$key])) {
$reflection = new ReflectionClass($nameOrObject);
static::$_cache_class_names[$key] = $reflection->getName();
}
return static::$_cache_class_names[$key];
} }
/** /**