Commit 80554ebf authored by catch's avatar catch

Issue #2720849 by joseph.olstad, quicksketch: D8 improve theme registry build performance

parent b9aa30a0
...@@ -134,7 +134,7 @@ function drupal_theme_rebuild() { ...@@ -134,7 +134,7 @@ function drupal_theme_rebuild() {
*/ */
function drupal_find_theme_functions($cache, $prefixes) { function drupal_find_theme_functions($cache, $prefixes) {
$implementations = []; $implementations = [];
$grouped_functions = \Drupal::service('theme.registry')->getPrefixGroupedUserFunctions(); $grouped_functions = \Drupal::service('theme.registry')->getPrefixGroupedUserFunctions($prefixes);
foreach ($cache as $hook => $info) { foreach ($cache as $hook => $info) {
foreach ($prefixes as $prefix) { foreach ($prefixes as $prefix) {
......
...@@ -633,8 +633,6 @@ protected function completeSuggestion($hook, array &$cache) { ...@@ -633,8 +633,6 @@ protected function completeSuggestion($hook, array &$cache) {
* @see ::processExtension() * @see ::processExtension()
*/ */
protected function postProcessExtension(array &$cache, ActiveTheme $theme) { protected function postProcessExtension(array &$cache, ActiveTheme $theme) {
$grouped_functions = $this->getPrefixGroupedUserFunctions();
// Gather prefixes. This will be used to limit the found functions to the // Gather prefixes. This will be used to limit the found functions to the
// expected naming conventions. // expected naming conventions.
$prefixes = array_keys((array) $this->moduleHandler->getModuleList()); $prefixes = array_keys((array) $this->moduleHandler->getModuleList());
...@@ -646,6 +644,8 @@ protected function postProcessExtension(array &$cache, ActiveTheme $theme) { ...@@ -646,6 +644,8 @@ protected function postProcessExtension(array &$cache, ActiveTheme $theme) {
} }
$prefixes[] = $theme->getName(); $prefixes[] = $theme->getName();
$grouped_functions = $this->getPrefixGroupedUserFunctions($prefixes);
// Collect all variable preprocess functions in the correct order. // Collect all variable preprocess functions in the correct order.
$suggestion_level = []; $suggestion_level = [];
$matches = []; $matches = [];
...@@ -744,15 +744,26 @@ public function destruct() { ...@@ -744,15 +744,26 @@ public function destruct() {
/** /**
* Gets all user functions grouped by the word before the first underscore. * Gets all user functions grouped by the word before the first underscore.
* *
* @param $prefixes
* An array of function prefixes by which the list can be limited.
* @return array * @return array
* Functions grouped by the first prefix. * Functions grouped by the first prefix.
*/ */
public function getPrefixGroupedUserFunctions() { public function getPrefixGroupedUserFunctions($prefixes = array()) {
$functions = get_defined_functions(); $functions = get_defined_functions();
// If a list of prefixes is supplied, trim down the list to those items
// only as efficiently as possible.
if ($prefixes) {
$theme_functions = preg_grep('/^(' . implode(')|(', $prefixes) . ')_/', $functions['user']);
}
else {
$theme_functions = $functions['user'];
}
$grouped_functions = []; $grouped_functions = [];
// Splitting user defined functions into groups by the first prefix. // Splitting user defined functions into groups by the first prefix.
foreach ($functions['user'] as $function) { foreach ($theme_functions as $function) {
list($first_prefix,) = explode('_', $function, 2); list($first_prefix,) = explode('_', $function, 2);
$grouped_functions[$first_prefix][] = $function; $grouped_functions[$first_prefix][] = $function;
} }
......
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