Index: includes/theme.inc =================================================================== --- includes/theme.inc (revision 4505) +++ includes/theme.inc (working copy) @@ -175,8 +175,9 @@ include_once './'. $theme->owner; } } - - $registry_callback($theme, $base_theme, $theme_engine); + // Do not load the full theme registry by default. + // @see theme_get_hook(). + //$registry_callback($theme, $base_theme, $theme_engine); } /** @@ -598,33 +599,34 @@ * An HTML string that generates the themed output. */ function theme() { + static $initialized; $args = func_get_args(); $hook = array_shift($args); static $hooks = NULL; - if (!isset($hooks)) { + if (!isset($initialized)) { + $initialized = TRUE; init_theme(); - $hooks = theme_get_registry(); } if (is_array($hook)) { foreach ($hook as $candidate) { - if (isset($hooks[$candidate])) { + if (theme_get_hook($candidate)) { break; } } $hook = $candidate; } - if (!isset($hooks[$hook])) { + if (!theme_get_hook($hook)) { return; } - $info = $hooks[$hook]; + $info = theme_get_hook($hook); global $theme_path; $temp = $theme_path; // point path_to_theme() to the currently used theme path: - $theme_path = $hooks[$hook]['theme path']; + $theme_path = $info['theme path']; // Include a file if the theme function or preprocess function is held elsewhere. if (!empty($info['include files'])) { @@ -677,7 +679,7 @@ if (isset($theme_engine)) { // If theme or theme engine is implementing this, it may have // a different extension and a different renderer. - if ($hooks[$hook]['type'] != 'module') { + if ($info['type'] != 'module') { if (function_exists($theme_engine .'_render_template')) { $render_function = $theme_engine .'_render_template'; } @@ -717,9 +719,9 @@ } if (empty($template_file)) { - $template_file = $hooks[$hook]['template'] . $extension; - if (isset($hooks[$hook]['path'])) { - $template_file = $hooks[$hook]['path'] .'/'. $template_file; + $template_file = $info['template'] . $extension; + if ($info['path']) { + $template_file = $info['path'] .'/'. $template_file; } } $output = $render_function($template_file, $variables); @@ -734,6 +736,44 @@ } /** + * Find the theme definition for a hook. + * + * This function maintains a cached subset of the theme registry which is built + * during calls to theme. To avoid loading the entire theme registry on every + * request for hooks which may not be called during normal site usage. + * + * @param $hook + * The theme hook being requested. + * @return + * The registry entry for the hook, or FALSE if none was found. + */ +function theme_get_hook($hook) { + global $theme; + static $hooks = array(); + if (empty($hooks)) { + if ($cached = cache_get("theme_registry:hooks:$theme")) { + $hooks = $cached->data; + } + } + if (isset($hooks[$hook])) { + return $hooks[$hook]; + } + else { + $registry = theme_get_registry(); + if (isset($registry[$hook])) { + $hooks[$hook] = $registry[$hook]; + cache_set("theme_registry:hooks:$theme", $hooks); + return $hooks[$hook]; + } + else { + $hooks[$hook] = FALSE; + cache_set("theme_registry:hooks:$theme", $hooks); + } + } + return FALSE; +} + +/** * Choose which template file to actually render. These are all suggested * templates from themes and modules. Theming implementations can occur on * multiple levels. All paths are checked to account for this.