Commit 3cbb4d38 authored by catch's avatar catch
Browse files

Issue #1853226 by yched, fubhy, tim.plunkett: Fixed Improve performance of CacheDecorator.

parent 08fc6f39
......@@ -65,14 +65,33 @@ public function __construct(DiscoveryInterface $decorated, $cache_key, $cache_bi
* Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinition().
*/
public function getDefinition($plugin_id) {
// Optimize for fast access to definitions if they are already in memory.
if (isset($this->definitions)) {
// Avoid using a ternary that would create a copy of the array.
if (isset($this->definitions[$plugin_id])) {
return $this->definitions[$plugin_id];
}
else {
return;
}
}
$definitions = $this->getDefinitions();
return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL;
// Avoid using a ternary that would create a copy of the array.
if (isset($definitions[$plugin_id])) {
return $definitions[$plugin_id];
}
}
/**
* Implements Drupal\Component\Plugin\Discovery\DicoveryInterface::getDefinitions().
*/
public function getDefinitions() {
// Optimize for fast access to definitions if they are already in memory.
if (isset($this->definitions)) {
return $this->definitions;
}
$definitions = $this->getCachedDefinitions();
if (!isset($definitions)) {
$definitions = $this->decorated->getDefinitions();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment