Index: system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.901
diff -u -r1.901 system.module
--- system.module	13 Mar 2010 06:55:50 -0000	1.901
+++ system.module	17 Mar 2010 12:22:31 -0000
@@ -2215,19 +2215,39 @@
 }
 
 /**
- * Helper function to scan and collect theme .info data and their engines.
- *
- * @return
- *   An associative array of themes information.
- */
-function _system_rebuild_theme_data() {
-  $themes_info = &drupal_static(__FUNCTION__, array());
+ * Scan theme directories for *.info files.
+ * The data is cached in a static variable.
+ * The data depends on nothing but the filesystem, so it doesn't need to be reset.
+ * 
+ * @return :array
+ *   Array of data from theme *.info files, keyed by theme name.
+ *   The information is cached.
+ *   The data depends on the install profile.
+ */
+function system_scan_theme_info() {
+  $raw_themes_info = &drupal_static(__FUNCTION__);
+  
+  if (!is_array($raw_themes_info)) {
+    $raw_themes_info = _system_scan_theme_info();
+  }
+  
+  // We don't return the original objects,
+  // because we don't want them to be manipulated by other functions.
+  $raw_themes_info_cloned = array();
+  foreach ($raw_themes_info as $key => $object) {
+    $raw_themes_info_cloned[$key] = clone $object;
+  }
+  return $raw_themes_info_cloned;
+}
 
-  if (empty($themes_info)) {
+/**
+ * Helper function for system_scan_theme_info()
+ */
+function _system_scan_theme_info() {
+  $raw_themes_info = array();
+  if (TRUE /* avoid indentation change for this patch */) {
     // Find themes
     $themes = drupal_system_listing('/\.info$/', 'themes');
-    // Find theme engines
-    $engines = drupal_system_listing('/\.engine$/', 'themes/engines');
 
     // Set defaults for theme info.
     $defaults = array(
@@ -2258,12 +2278,34 @@
       'php' => DRUPAL_MINIMUM_PHP,
     );
 
-    $sub_themes = array();
     // Read info files for each theme
     foreach ($themes as $key => $theme) {
-      $themes[$key]->filename = $theme->uri;
-      $themes[$key]->info = drupal_parse_info_file($theme->uri) + $defaults;
+      $raw_themes_info[$key]->filename = $theme->uri;
+      $raw_themes_info[$key]->info = drupal_parse_info_file($theme->uri) + $defaults;
+    }
+  }
+  
+  return $raw_themes_info;
+}
 
+/**
+ * Helper function to scan and collect theme .info data and their engines.
+ *
+ * @return
+ *   An associative array of themes information.
+ */
+function _system_rebuild_theme_data() {
+  $themes_info = &drupal_static(__FUNCTION__, array());
+
+  if (empty($themes_info) {
+    // Find themes
+    $themes = system_scan_theme_info();
+    // Find theme engines. drupal_system_listing() can have its own cache.
+    $engines = drupal_system_listing('/\.engine$/', 'themes/engines');
+
+    $sub_themes = array();
+    // Read info files for each theme
+    foreach ($themes as $key => $theme) {
       // Invoke hook_system_info_alter() to give installed modules a chance to
       // modify the data in the .info files if necessary.
       $type = 'theme';
@@ -2341,8 +2383,14 @@
 
     $themes_info = $themes;
   }
-
-  return $themes_info;
+  
+  // We don't return the original objects,
+  // because we don't want them to be manipulated by other functions.
+  $themes_info_cloned = array();
+  foreach ($themes_info as $key => $object) {
+    $themes_info_cloned[$key] = clone $object;
+  }
+  return $themes_info_cloned;
 }
 
 /**

