=== modified file 'includes/bootstrap.inc'
--- includes/bootstrap.inc	2008-04-14 17:48:33 +0000
+++ includes/bootstrap.inc	2008-04-18 21:24:32 +0000
@@ -365,27 +365,31 @@ function conf_init() {
  *   than by consulting the database.
  *
  * @return
- *   The filename of the requested item.
+ *   The filename of the requested item. Or an array of files of the given
+ *   type if $name was not specified.
  */
-function drupal_get_filename($type, $name, $filename = NULL) {
-  static $files = array();
+function drupal_get_filename($type, $name = NULL, $filename = NULL) {
+  static $files = array(), $list = array();
 
-  if (!isset($files[$type])) {
-    $files[$type] = array();
+  if (!isset($list[$type])) {
+    $list[$type] = array();
+  }
+  if (!isset($name)) {
+    return $list[$type];
+  }
+  if (isset($files[$type][$name])) {
+    return $files[$type][$name];
   }
 
   if (!empty($filename) && file_exists($filename)) {
-    $files[$type][$name] = $filename;
-  }
-  elseif (isset($files[$type][$name])) {
-    // nothing
+    $return = $filename;
   }
   // Verify that we have an active database connection, before querying
   // the database.  This is required because this function is called both
   // before we have a database connection (i.e. during installation) and
   // when a database connection fails.
-  elseif (db_is_active() && (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file))) {
-    $files[$type][$name] = $file;
+  elseif (function_exists('db_is_active') && db_is_active() && (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file))) {
+    $return = $file;
   }
   else {
     // Fallback to searching the filesystem if the database connection is
@@ -396,14 +400,16 @@ function drupal_get_filename($type, $nam
 
     foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
       if (file_exists($file)) {
-        $files[$type][$name] = $file;
+        $return = $file;
         break;
       }
     }
   }
 
-  if (isset($files[$type][$name])) {
-    return $files[$type][$name];
+  if ($return) {
+    $files[$type][$name] = $return;
+    $list[$type][$name] = $name;
+    return $return;
   }
 }
 
@@ -518,10 +524,9 @@ 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) {
-    drupal_load('module', $module);
-    module_invoke($module, $hook);
-  }
+  module_fetch_all(TRUE);
+  module_load_all();
+  module_invoke_all($hook);
 }
 
 /**
@@ -998,6 +1003,9 @@ function _drupal_bootstrap($phase) {
 
     case DRUPAL_BOOTSTRAP_PATH:
       require_once './includes/path.inc';
+      // We need to know whether path module exists, however it is a waste of
+      // queries not to load information about all modules.
+      module_fetch_all();
       // Initialize $_GET['q'] prior to loading modules and invoking hook_init().
       drupal_init_path();
       break;

=== modified file 'includes/module.inc'
--- includes/module.inc	2008-04-16 11:35:51 +0000
+++ includes/module.inc	2008-04-18 21:26:31 +0000
@@ -10,12 +10,34 @@
  * 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);
   }
 }
 
 /**
+ * Load an absolute minimal set of modules.
+ */
+function module_load_minimal() {
+  foreach (array('system', 'filter') as $module) {
+    drupal_load('module', $module);
+  }
+}
+
+function module_fetch_all($bootstrap = FALSE) {
+  static $done;
+  if (!isset($done[$bootstrap])) {
+    $done[$bootstrap] = TRUE;
+    $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = %d ORDER BY weight ASC, filename ASC", $bootstrap);
+    while ($module = db_fetch_object($result)) {
+      if (file_exists($module->filename)) {
+        drupal_get_filename('module', $module->name, $module->filename);
+      }
+    }
+  }
+}
+
+/**
  * Call a function repeatedly with each module in turn as an argument.
  */
 function module_iterate($function, $argument = '') {
@@ -28,51 +50,19 @@ function module_iterate($function, $argu
  * Collect a list of all loaded modules. During the bootstrap, return only
  * vital modules. See bootstrap.inc
  *
- * @param $refresh
- *   Whether to force the module list to be regenerated (such as after the
- *   administrator has changed the system settings).
- * @param $bootstrap
- *   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.
- * @param $fixed_list
- *   (Optional) Override the module list with the given modules. Stays until the
- *   next call with $refresh = TRUE.
  * @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($sort = FALSE) {
+  static $stored_list, $sorted_list;
 
-  if ($refresh || $fixed_list) {
-    unset($sorted_list);
-    $list = array();
-    if ($fixed_list) {
-      foreach ($fixed_list as $name => $module) {
-        drupal_get_filename('module', $name, $module['filename']);
-        $list[$name] = $name;
-      }
-    }
-    else {
-      if ($bootstrap) {
-        $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
-      }
-      else {
-        $result = db_query("SELECT name, filename 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)) {
-          drupal_get_filename('module', $module->name, $module->filename);
-          $list[$module->name] = $module->name;
-        }
-      }
-    }
-  }
+  $list = drupal_get_filename('module');
   if ($sort) {
-    if (!isset($sorted_list)) {
+    if ($stored_list != $list || !isset($sorted_list)) {
       $sorted_list = $list;
       ksort($sorted_list);
     }
@@ -221,7 +211,7 @@ function _module_build_dependencies($fil
  */
 function module_exists($module) {
   $list = module_list();
-  return array_key_exists($module, $list);
+  return isset($list[$module]);
 }
 
 /**
@@ -289,8 +279,6 @@ function module_enable($module_list) {
   }
 
   if (!empty($invoke_modules)) {
-    // Refresh the module list to include the new enabled module.
-    module_list(TRUE, FALSE);
     // Force to regenerate the stored list of hook implementations.
     module_implements('', FALSE, TRUE);
   }
@@ -330,8 +318,6 @@ function module_disable($module_list) {
   }
 
   if (!empty($invoke_modules)) {
-    // Refresh the module list to exclude the disabled modules.
-    module_list(TRUE, FALSE);
     // Force to regenerate the stored list of hook implementations.
     module_implements('', FALSE, TRUE);
   }
@@ -404,7 +390,7 @@ function module_implements($hook, $sort 
 
   if (!isset($implementations[$hook])) {
     $implementations[$hook] = array();
-    $list = module_list(FALSE, TRUE, $sort);
+    $list = module_list($sort);
     foreach ($list as $module) {
       if (module_hook($module, $hook)) {
         $implementations[$hook][] = $module;

=== modified file 'includes/theme.maintenance.inc'
--- includes/theme.maintenance.inc	2008-04-14 17:48:33 +0000
+++ includes/theme.maintenance.inc	2008-04-18 17:51:43 +0000
@@ -36,13 +36,7 @@ function _drupal_maintenance_theme() {
     $theme = 'minnelli';
   }
   else {
-    // 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);
-    drupal_load('module', 'system');
-    drupal_load('module', 'filter');
-
+    module_load_minimal();
     $theme = variable_get('maintenance_theme', 'minnelli');
   }
 

=== modified file 'install.php'
--- install.php	2008-04-14 17:48:33 +0000
+++ install.php	2008-04-18 17:51:36 +0000
@@ -34,11 +34,7 @@ function install_main() {
 
   // Load module basics (needed for hook invokes).
   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);
-  drupal_load('module', 'system');
-  drupal_load('module', 'filter');
+  module_load_minimal();
 
   // Set up theme system for the maintenance page.
   drupal_maintenance_theme();

=== modified file 'modules/system/system.admin.inc'
--- modules/system/system.admin.inc	2008-04-16 11:35:51 +0000
+++ modules/system/system.admin.inc	2008-04-18 17:53:49 +0000
@@ -889,7 +889,7 @@ function system_modules_submit($form, &$
   }
   drupal_install_modules($new_modules);
 
-  $current_module_list = module_list(TRUE, FALSE);
+  $current_module_list = module_list();
   if ($old_module_list != $current_module_list) {
     drupal_set_message(t('The configuration options have been saved.'));
   }

=== modified file 'modules/user/user.admin.inc'
--- modules/user/user.admin.inc	2008-04-14 17:48:33 +0000
+++ modules/user/user.admin.inc	2008-04-18 17:54:15 +0000
@@ -517,7 +517,7 @@ function user_admin_perm($form_state, $r
   // Render role/permission overview:
   $options = array();
   $hide_descriptions = !system_admin_compact_mode();
-  foreach (module_list(FALSE, FALSE, TRUE) as $module) {
+  foreach (module_list(TRUE) as $module) {
     if ($permissions = module_invoke($module, 'perm')) {
       $form['permission'][] = array(
         '#value' => $module,

