diff -u b/core/lib/Drupal/Core/Theme/Registry.php b/core/lib/Drupal/Core/Theme/Registry.php --- b/core/lib/Drupal/Core/Theme/Registry.php +++ b/core/lib/Drupal/Core/Theme/Registry.php @@ -138,6 +138,13 @@ protected $themeManager; /** + * User functions grouped by the word before first underscore. + * + * @var array + */ + protected $groupedFunctions; + + /** * Constructs a \Drupal\Core\Theme\Registry object. * * @param string $root @@ -573,7 +580,7 @@ * @see ::processExtension() */ protected function postProcessExtension(array &$cache, ActiveTheme $theme) { - $grouped_functions = drupal_group_functions_by_prefix(); + $grouped_functions = $this->getPrefixGroupedUserFunctions(); // Gather prefixes. This will be used to limit the found functions to the // expected naming conventions. @@ -683,6 +690,28 @@ } /** + * Get all user functions grouped by word before first underscore. + * + * @return array + * Functions grouped by the first prefix. + */ + public function getPrefixGroupedUserFunctions() { + if (!$this->groupedFunctions) { + $functions = get_defined_functions(); + + $this->groupedFunctions = []; + // Splitting user defined functions into groups by the first prefix. + foreach ($functions['user'] as $function) { + list($first_prefix,) = explode('_', $function, 2); + $this->groupedFunctions[$first_prefix][] = $function; + } + } + + return $this->groupedFunctions; + } + + + /** * Wraps drupal_get_path(). * * @param string $module only in patch2: unchanged: --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -172,16 +172,7 @@ function drupal_find_theme_functions($cache, $prefixes) { * Functions grouped by the first prefix. */ function drupal_group_functions_by_prefix() { - $functions = get_defined_functions(); - - $grouped_functions = []; - // Splitting user defined functions into groups by the first prefix. - foreach ($functions['user'] as $function) { - list($first_prefix,) = explode('_', $function, 2); - $grouped_functions[$first_prefix][] = $function; - } - - return $grouped_functions; + \Drupal::service('theme.registry')->getPrefixGroupedUserFunctions(); } /**