diff --git a/includes/module.inc b/includes/module.inc --- a/includes/module.inc +++ b/includes/module.inc @@ -694,6 +694,30 @@ function module_hook($module, $hook) { function module_implements($hook, $sort = FALSE, $reset = FALSE) { // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; + static $full_bootstrap; + + // This ensures that this clause is only called once after full bootstrap has + // happened. + if (empty($full_bootstrap)) { + $full_bootstrap = drupal_bootstrap(NULL, FALSE) == DRUPAL_BOOTSTRAP_FULL; + + // In case we are pre-bootstrap, ensure to use a different static implementation. + if (empty($full_bootstrap)) { + if (!isset($drupal_static_fast)) { + $drupal_static_fast['implementations'] = &drupal_static('module_implements_boot'); + } + } + else if (isset($drupal_static_fast)) { + // The first time we come here after full bootstrap, but with + // $drupal_static_fast already populated, we reset the + // $drupal_static_fast variable. + unset($drupal_static_fast); + + // And clear any existing drupal_alter() cache. + drupal_static_reset('drupal_alter'); + } + } + if (!isset($drupal_static_fast)) { $drupal_static_fast['implementations'] = &drupal_static(__FUNCTION__); } @@ -726,6 +750,12 @@ function module_implements($hook, $sort = FALSE, $reset = FALSE) { } else { $implementations = $implementations->data; + // In case we don't have full bootstrap, yet, store the data also + // in the future static as that cache_get is always the full cache. + if (!$full_bootstrap) { + $module_implements_cache = &drupal_static('module_implements'); + $module_implements_cache['implementations'] = $implementations; + } } }