Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.117
diff -u -p -r1.117 install.php
--- install.php	14 Apr 2008 17:48:33 -0000	1.117
+++ install.php	16 Apr 2008 05:11:19 -0000
@@ -36,7 +36,7 @@ function install_main() {
   include_once './includes/module.inc';
   $module_list['system']['filename'] = 'modules/system/system.module';
   $module_list['filter']['filename'] = 'modules/filter/filter.module';
-  module_list(TRUE, FALSE, FALSE, $module_list);
+  module_list(FALSE, FALSE, FALSE, $module_list);
   drupal_load('module', 'system');
   drupal_load('module', 'filter');
 
Index: update.php
===================================================================
RCS file: /cvs/drupal/drupal/update.php,v
retrieving revision 1.254
diff -u -p -r1.254 update.php
--- update.php	14 Apr 2008 17:48:33 -0000	1.254
+++ update.php	16 Apr 2008 05:11:20 -0000
@@ -584,7 +584,7 @@ if (empty($op)) {
   include_once './includes/module.inc';
   $module_list['system']['filename'] = 'modules/system/system.module';
   $module_list['filter']['filename'] = 'modules/filter/filter.module';
-  module_list(TRUE, FALSE, FALSE, $module_list);
+  module_list(FALSE, FALSE, FALSE, $module_list);
   drupal_load('module', 'system');
   drupal_load('module', 'filter');
 
Index: ./includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.208
diff -u -p -r1.208 bootstrap.inc
--- ./includes/bootstrap.inc	14 Apr 2008 17:48:33 -0000	1.208
+++ ./includes/bootstrap.inc	16 Apr 2008 05:11:21 -0000
@@ -518,7 +518,7 @@ function page_get_cache() {
  *   The name of the bootstrap hook we wish to invoke.
  */
 function bootstrap_invoke_all($hook) {
-  foreach (module_list(TRUE, TRUE) as $module) {
+  foreach (module_list(FALSE, TRUE) as $module) {
     drupal_load('module', $module);
     module_invoke($module, $hook);
   }
Index: ./includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.116
diff -u -p -r1.116 module.inc
--- ./includes/module.inc	14 Apr 2008 17:48:33 -0000	1.116
+++ ./includes/module.inc	16 Apr 2008 05:11:30 -0000
@@ -10,7 +10,7 @@
  * Load all the modules that have been enabled in the system table.
  */
 function module_load_all() {
-  foreach (module_list(TRUE, FALSE) as $module) {
+  foreach (module_list() as $module) {
     drupal_load('module', $module);
   }
 }
@@ -26,7 +26,7 @@ function module_iterate($function, $argu
 
 /**
  * Collect a list of all loaded modules. During the bootstrap, return only
- * vital modules. See bootstrap.inc
+ * vital modules. See bootstrap.inc.
  *
  * @param $refresh
  *   Whether to force the module list to be regenerated (such as after the
@@ -35,56 +35,71 @@ function module_iterate($function, $argu
  *   Whether to return the reduced set of modules loaded in "bootstrap mode"
  *   for cached pages. See bootstrap.inc.
  * @param $sort
- *   By default, modules are ordered by weight and filename, settings this option
- *   to TRUE, module list will be ordered by module name.
+ *   By default, modules are ordered by weight and filename, but if this
+ *   option is set to TRUE, the list will be ordered by module name instead.
  * @param $fixed_list
- *   (Optional) Override the module list with the given modules. Stays until the
- *   next call with $refresh = TRUE.
+ *   (Optional) Override the module list with the given modules.
  * @return
  *   An associative array whose keys and values are the names of all loaded
  *   modules.
  */
-function module_list($refresh = FALSE, $bootstrap = TRUE, $sort = FALSE, $fixed_list = NULL) {
-  static $list, $sorted_list;
+function module_list($refresh = FALSE, $bootstrap = FALSE, $sort = FALSE, $fixed_list = NULL) {
+  static $list = array(), $sorted_list = array();
 
-  if ($refresh || $fixed_list) {
-    unset($sorted_list);
+  // Clear the module lists if we need to regenerate them.
+  if ($refresh) {
     $list = array();
-    if ($fixed_list) {
-      foreach ($fixed_list as $name => $module) {
-        drupal_get_filename('module', $name, $module['filename']);
-        $list[$name] = $name;
-      }
+    $sorted_list = array();
+  }
+
+  // Process and return the input module list, if one was provided.
+  if (isset($fixed_list)) {
+    $module_list = array();
+    foreach ($fixed_list as $name => $module) {
+      drupal_get_filename('module', $name, $module['filename']);
+      $module_list[$name] = $name;
+    }
+    if ($sort) {
+      ksort($module_list);
+    }
+    return $module_list;
+  }
+
+  // Generate the list of modules.
+  if (!isset($list[$bootstrap])) {
+    $list[$bootstrap] = array();
+    if ($bootstrap) {
+      $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
     }
     else {
-      if ($bootstrap) {
-        $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
-      }
-      else {
-        $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
-      }
-      while ($module = db_fetch_object($result)) {
-        if (file_exists($module->filename)) {
-          // Determine the current throttle status and see if the module should be
-          // loaded based on server load. We have to directly access the throttle
-          // variables, since throttle.module may not be loaded yet.
-          $throttle = ($module->throttle && variable_get('throttle_level', 0) > 0);
-          if (!$throttle) {
-            drupal_get_filename('module', $module->name, $module->filename);
-            $list[$module->name] = $module->name;
-          }
+      $result = db_query("SELECT name, filename, throttle FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
+    }
+    while ($module = db_fetch_object($result)) {
+      if (file_exists($module->filename)) {
+        // Determine the current throttle status and see if the module should be
+        // loaded based on server load. We have to directly access the throttle
+        // variables, since throttle.module may not be loaded yet.
+        $throttle = ($module->throttle && variable_get('throttle_level', 0) > 0);
+        if (!$throttle) {
+          drupal_get_filename('module', $module->name, $module->filename);
+          $list[$bootstrap][$module->name] = $module->name;
         }
       }
     }
   }
+
+  // Sort the module list and return it, if necessary.
   if ($sort) {
-    if (!isset($sorted_list)) {
-      $sorted_list = $list;
-      ksort($sorted_list);
+    if (!isset($sorted_list[$bootstrap])) {
+      $temporary_list = $list[$bootstrap];
+      ksort($temporary_list);
+      $sorted_list[$bootstrap] = $temporary_list;
     }
-    return $sorted_list;
+    return $sorted_list[$bootstrap];
   }
-  return $list;
+
+  // Otherwise, return the unsorted list.
+  return $list[$bootstrap];
 }
 
 /**
@@ -297,7 +312,7 @@ function module_enable($module_list) {
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to include the new enabled module.
-    module_list(TRUE, FALSE);
+    module_list(TRUE);
     // Force to regenerate the stored list of hook implementations.
     module_implements('', FALSE, TRUE);
   }
@@ -338,7 +353,7 @@ function module_disable($module_list) {
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to exclude the disabled modules.
-    module_list(TRUE, FALSE);
+    module_list(TRUE);
     // Force to regenerate the stored list of hook implementations.
     module_implements('', FALSE, TRUE);
   }
@@ -411,7 +426,7 @@ function module_implements($hook, $sort 
 
   if (!isset($implementations[$hook])) {
     $implementations[$hook] = array();
-    $list = module_list(FALSE, TRUE, $sort);
+    $list = module_list(FALSE, FALSE, $sort);
     foreach ($list as $module) {
       if (module_hook($module, $hook)) {
         $implementations[$hook][] = $module;
Index: ./includes/theme.maintenance.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v
retrieving revision 1.12
diff -u -p -r1.12 theme.maintenance.inc
--- ./includes/theme.maintenance.inc	14 Apr 2008 17:48:33 -0000	1.12
+++ ./includes/theme.maintenance.inc	16 Apr 2008 05:11:32 -0000
@@ -39,7 +39,7 @@ function _drupal_maintenance_theme() {
     // Load module basics (needed for hook invokes).
     $module_list['system']['filename'] = 'modules/system/system.module';
     $module_list['filter']['filename'] = 'modules/filter/filter.module';
-    module_list(TRUE, FALSE, FALSE, $module_list);
+    module_list(FALSE, FALSE, FALSE, $module_list);
     drupal_load('module', 'system');
     drupal_load('module', 'filter');
 
Index: ./modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.70
diff -u -p -r1.70 system.admin.inc
--- ./modules/system/system.admin.inc	14 Apr 2008 17:48:41 -0000	1.70
+++ ./modules/system/system.admin.inc	16 Apr 2008 05:11:54 -0000
@@ -916,7 +916,7 @@ function system_modules_submit($form, &$
   }
   drupal_install_modules($new_modules);
 
-  $current_module_list = module_list(TRUE, FALSE);
+  $current_module_list = module_list(TRUE);
   if ($old_module_list != $current_module_list) {
     drupal_set_message(t('The configuration options have been saved.'));
   }
