Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.417
diff -u -r1.417 system.install
--- modules/system/system.install	8 Nov 2009 09:29:07 -0000	1.417
+++ modules/system/system.install	8 Nov 2009 16:42:11 -0000
@@ -1567,7 +1567,8 @@
     ),
     'primary key' => array('filename'),
     'indexes' => array(
-      'system_list' => array('status', 'weight', 'name'),
+      'modules' => array('type', 'status', 'weight', 'name'),
+      'bootstrap' => array('type', 'status', 'bootstrap', 'weight', 'name'),
       'type_name' => array('type', 'name'),
     ),
   );
@@ -2195,15 +2196,14 @@
 }
 
 /**
- * Shorten the {system}.type column and modify indexes.
+ * Shorten the {system}.type column and add an index on type and name.
  */
 function system_update_7018() {
   db_drop_index('system', 'modules');
   db_drop_index('system', 'type_name');
-  db_drop_index('system', 'bootstrap');
   db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
+  db_add_index('system', 'modules', array('type', 'status', 'weight', 'name'));
   db_add_index('system', 'type_name', array('type', 'name'));
-  db_add_index('system', 'system_list', array('status', 'weight', 'name'));
 }
 
 /**
Index: includes/theme.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.inc,v
retrieving revision 1.550
diff -u -r1.550 theme.inc
--- includes/theme.inc	8 Nov 2009 12:43:41 -0000	1.550
+++ includes/theme.inc	8 Nov 2009 16:42:10 -0000
@@ -562,7 +562,6 @@
 
   if ($refresh) {
     $list = array();
-    drupal_static_reset('system_list');
   }
 
   if (empty($list)) {
@@ -571,7 +570,8 @@
     // Extract from the database only when it is available.
     // Also check that the site is not in the middle of an install or update.
     if (db_is_active() && !defined('MAINTENANCE_MODE')) {
-      foreach (system_list('theme') as $theme) {
+      $result = db_query("SELECT * FROM {system} WHERE type = :theme", array(':theme' => 'theme'));
+      foreach ($result as $theme) {
         if (file_exists($theme->filename)) {
           $theme->info = unserialize($theme->info);
           $themes[] = $theme;
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.167
diff -u -r1.167 module.inc
--- includes/module.inc	8 Nov 2009 09:31:10 -0000	1.167
+++ includes/module.inc	8 Nov 2009 16:42:09 -0000
@@ -69,10 +69,21 @@
       // locations in the file system. The ordering here must also be
       // consistent with the one used in module_implements().
       if ($bootstrap) {
-        $list = system_list('bootstrap');
+        $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, name ASC");
       }
       else {
-        $list = system_list('module');
+        $result = db_query("SELECT name, filename FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, name ASC");
+      }
+      foreach ($result as $module) {
+        if (file_exists($module->filename)) {
+          // First call drupal_get_filename() to prime the static cache for
+          // later lookups of the module path. Since we've already queried for
+          // the filename and can pass that in as an argument, this avoids a
+          // database hit for every module when drupal_get_filename() is
+          // subsequently called by drupal_load().
+          drupal_get_filename('module', $module->name, $module->filename);
+          $list[$module->name] = $module->name;
+        }
       }
     }
   }
@@ -87,49 +98,6 @@
 }
 
 /**
- * Build a list of bootstrap modules and enabled modules and themes.
- *
- * @param $type
- *   The type of list to return, either 'module', 'bootstrap', or 'theme'.
- *
- * @return
- *   An associative array of modules or themes, keyed by name, with the minimum
- *   data required to bootstrap.
- *
- * @see module_list()
- * @see list_themes()
- */
-function system_list($type) {
-  $lists = &drupal_static(__FUNCTION__);
-
-  if (!isset($lists)) {
-    $lists = array('bootstrap' => array(), 'module' => array(), 'theme' => array());
-    $result = db_query("SELECT * FROM {system} WHERE status = 1 ORDER BY weight ASC, name ASC");
-    foreach ($result as $record) {
-      // Build a list of all enabled modules.
-      if ($record->type == 'module') {
-        $lists['module'][$record->name] = $record->name;
-        // Build a separate array of modules required for bootstrap.
-        if ($record->bootstrap) {
-          $lists['bootstrap'][$record->name] = $record->name;
-        }
-      }
-      // Build a list of enabled themes.
-      if ($record->type == 'theme') {
-        $lists['theme'][$record->name] = $record;
-      }
-
-      // Additionally prime drupal_get_filename() with the filename and type
-      // for each record, this prevents subsequent database lookups when
-      // drupal_get_filename() is called without the 'file' argument.
-      drupal_get_filename($record->type, $record->name, $record->filename);
-    }
-  }
-
-  return $lists[$type];
-}
-
-/**
  * Find dependencies any level deep and fill in required by information too.
  *
  * @param $files
@@ -268,7 +236,6 @@
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to exclude the disabled modules.
-    drupal_static_reset('system_list');
     module_list(TRUE);
     module_implements('', FALSE, TRUE);
     // Force to regenerate the stored list of hook implementations.
@@ -329,7 +296,6 @@
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to exclude the disabled modules.
-    drupal_static_reset('system_list');
     module_list(TRUE);
     module_implements('', FALSE, TRUE);
     // Invoke hook_modules_disabled before disabling modules,
