Minor performance improvement for PluginManager.

Suggested by @tobias-kuendig in #4337, implemented because normalizeIdentifier() would be called more frequently by merging #4838.
This commit is contained in:
Luke Towers 2020-03-31 00:36:33 -06:00
parent 52cdfda935
commit 243c835c24
1 changed files with 12 additions and 5 deletions

View File

@ -38,6 +38,11 @@ class PluginManager
*/
protected $pathMap = [];
/**
* @var array A map of normalized plugin identifiers [lowercase.identifier => Normalized.Identifier]
*/
protected $normalizedMap = [];
/**
* @var bool Check if all plugins have had the register() method called.
*/
@ -157,6 +162,7 @@ class PluginManager
$this->plugins[$classId] = $classObj;
$this->pathMap[$classId] = $path;
$this->normalizedMap[strtolower($classId)] = $classId;
return $classObj;
}
@ -441,15 +447,16 @@ class PluginManager
/**
* Takes a human plugin code (acme.blog) and makes it authentic (Acme.Blog)
* @param string $id
* Returns the provided identifier if a match isn't found
*
* @param string $identifier
* @return string
*/
public function normalizeIdentifier($identifier)
{
foreach ($this->plugins as $id => $object) {
if (strtolower($id) == strtolower($identifier)) {
return $id;
}
$id = strtolower($identifier);
if (isset($this->normalizedMap[$id])) {
return $this->normalizedMap[$id];
}
return $identifier;