From 99233a9c991635e801aebc276e4e2975b6ba9e20 Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Tue, 29 Mar 2005 21:01:47 +0000
Subject: [PATCH] - Patch #19590 by Moshe: lazy initialization of the theme
 system.  Improves   performance of pages that don't need the theme system
 (such as RSS feeds)   and makes it easier to set a custom theme.

---
 includes/common.inc | 3 ---
 includes/theme.inc  | 8 ++++++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/includes/common.inc b/includes/common.inc
index cfa48aa9d26b..f3abbac85a52 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -1905,7 +1905,4 @@ function clone($object) {
 // Initialize the localization system.
 $locale = locale_initialize();
 
-// Initialize the enabled theme.
-$theme = init_theme();
-
 ?>
diff --git a/includes/theme.inc b/includes/theme.inc
index 11004306ba07..14b2181e3040 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -171,8 +171,12 @@ function list_theme_engines($refresh = FALSE) {
  *   An HTML string that generates the themed output.
  */
 function theme() {
-  global $theme;
-  global $theme_engine;
+  global $theme, $theme_engine;
+
+  if (!$theme) {
+    // Initialize the enabled theme.
+    $theme = init_theme();
+  }
 
   $args = func_get_args();
   $function = array_shift($args);
-- 
GitLab