Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.254
diff -u -p -r1.254 bootstrap.inc
--- includes/bootstrap.inc	24 Nov 2008 10:41:39 -0000	1.254
+++ includes/bootstrap.inc	29 Nov 2008 22:45:37 -0000
@@ -1513,7 +1513,7 @@ function _registry_check_code($type, $na
   // This function may get called when the default database is not active, but
   // there is no reason we'd ever want to not use the default database for
   // this query.
-  $file = Database::getConnection('default')->query("SELECT filename FROM {registry} WHERE name = :name AND type = :type", array(
+  $file = Database::getConnection('default')->query("SELECT filename FROM {registry} WHERE name = :name AND type = :type AND enabled = 1", array(
       ':name' => $name,
       ':type' => $type,
     ))
Index: includes/install.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.inc,v
retrieving revision 1.77
diff -u -p -r1.77 install.inc
--- includes/install.inc	24 Nov 2008 10:41:39 -0000	1.77
+++ includes/install.inc	29 Nov 2008 22:45:39 -0000
@@ -554,6 +554,7 @@ function drupal_install_init_database() 
     foreach (glob(DRUPAL_ROOT . '/includes/database/' . $driver . '/*.inc') as $include_file) {
       require_once $include_file;
     }
+    $included = TRUE;
   }
 }
 
@@ -573,7 +574,6 @@ function drupal_install_system() {
   $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED;
   db_query("INSERT INTO {system} (filename, name, type, owner, status, schema_version) VALUES('%s', '%s', '%s', '%s', %d, %d)", $system_path . '/system.module', 'system', 'module', '', 1, $system_version);
   // Now that we've installed things properly, bootstrap the full Drupal environment
-  drupal_install_init_database();
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
   module_rebuild_cache();
 }
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.134
diff -u -p -r1.134 module.inc
--- includes/module.inc	24 Nov 2008 10:41:39 -0000	1.134
+++ includes/module.inc	29 Nov 2008 22:45:47 -0000
@@ -427,7 +427,7 @@ function module_implements($hook, $sort 
       $cached_hooks = count($implementations);
     }
     if (!isset($implementations[$hook])) {
-      $implementations[$hook] = db_query("SELECT module FROM {registry} WHERE type = 'function' AND suffix = :hook ORDER BY weight, module", array(':hook' => $hook))->fetchCol();
+      $implementations[$hook] = db_query("SELECT module FROM {registry} WHERE type = 'function' AND enabled = 1 AND suffix = :hook ORDER BY weight, module", array(':hook' => $hook))->fetchCol();
     }
     foreach ($implementations[$hook] as $module) {
       $function = $module . '_' . $hook;
Index: includes/registry.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/registry.inc,v
retrieving revision 1.9
diff -u -p -r1.9 registry.inc
--- includes/registry.inc	16 Nov 2008 19:41:14 -0000	1.9
+++ includes/registry.inc	29 Nov 2008 22:45:47 -0000
@@ -42,25 +42,25 @@ function _registry_rebuild() {
   // Get the list of files we are going to parse.
   $files = array();
   foreach (module_rebuild_cache() as $module) {
-    if ($module->status) {
-      $dir = dirname($module->filename);
-      foreach ($module->info['files'] as $file) {
-        $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight);
-      }
+    $dir = dirname($module->filename);
+    foreach ($module->info['files'] as $file) {
+      $files["$dir/$file"] = array('module' => $module->name, 'weight' => $module->weight, 'enabled' => $module->status);
     }
   }
   foreach (file_scan_directory('includes', '/\.inc$/') as $filename => $file) {
-    $files["$filename"] = array('module' => '', 'weight' => 0);
+    $files["$filename"] = array('module' => '', 'weight' => 0, 'enabled' => 1);
   }
 
   foreach (registry_get_parsed_files() as $filename => $file) {
     // Add the md5 to those files we've already parsed.
+    // Add a flag indicating whether we need to update the 
+    // enabled status for resources in this file.
     if (isset($files[$filename])) {
       $files[$filename]['md5'] = $file['md5'];
+      $files[$filename]['update_enabled_status'] = $file['enabled'] != $files[$filename]['enabled'];
     }
     else {
-      // Flush the registry of resources in files that are no longer on disc
-      // or don't belong to installed modules.
+      // Flush the registry of resources in files that are no longer on disc.
       db_delete('registry')
         ->condition('filename', $filename)
         ->execute();
@@ -97,7 +97,7 @@ function _registry_rebuild() {
 function registry_get_parsed_files() {
   $files = array();
   // We want the result as a keyed array.
-  $files = db_query("SELECT * FROM {registry_file}")->fetchAllAssoc('filename', PDO::FETCH_ASSOC);
+  $files = db_query("SELECT DISTINCT rf.filename, rf.md5, r.enabled FROM {registry_file} rf INNER JOIN registry r ON r.filename = rf.filename")->fetchAllAssoc('filename', PDO::FETCH_ASSOC);
   return $files;
 }
 
@@ -117,13 +117,15 @@ function _registry_parse_files($files) {
       $parsed_files[] = $filename;
       // We update the md5 after we've saved the files resources rather than here, so if we
       // don't make it through this rebuild, the next run will reparse the file.
-      _registry_parse_file($filename, $contents, $file['module'], $file['weight']);
-      $file['md5'] = $md5;
+      _registry_parse_file($filename, $contents, $file['enabled'], $file['module'], $file['weight']);
       db_merge('registry_file')
         ->key(array('filename' => $filename))
         ->fields(array('md5' => $md5))
         ->execute();
     }
+    else if ($file['update_enabled_status']) {
+      db_query("UPDATE {registry} SET enabled = %d WHERE filename = '%s'", $files[$filename]['enabled'], $filename);
+    }
   }
   return $parsed_files;
 }
@@ -140,7 +142,7 @@ function _registry_parse_files($files) {
  * @param $weight
  *   (optional) Weight of the module.
  */
-function _registry_parse_file($filename, $contents, $module = '', $weight = 0) {
+function _registry_parse_file($filename, $contents, $enabled, $module = '', $weight = 0) {
   static $map = array(T_FUNCTION => 'function', T_CLASS => 'class', T_INTERFACE => 'interface');
   // Delete registry entries for this file, so we can insert the new resources.
   db_delete('registry')
@@ -166,6 +168,7 @@ function _registry_parse_file($filename,
           'module' => $module,
           'suffix' => $suffix,
           'weight' => $weight,
+          'enabled' => $enabled,
         );
         // Because some systems, such as cache, currently use duplicate function
         // names in separate files an insert query cannot be used here as it
@@ -181,7 +184,6 @@ function _registry_parse_file($filename,
           ->fields($fields)
           ->execute();
 
-        // We skip the body because classes may contain functions.
         _registry_skip_body($tokens);
       }
     }
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.63
diff -u -p -r1.63 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	29 Nov 2008 09:33:51 -0000	1.63
+++ modules/simpletest/drupal_web_test_case.php	29 Nov 2008 22:45:53 -0000
@@ -777,6 +777,8 @@ class DrupalWebTestCase {
 
     include_once DRUPAL_ROOT . '/includes/install.inc';
     drupal_install_system();
+    
+    $this->preloadRegistry();
 
     // Add the specified modules to the list of modules in the default profile.
     $args = func_get_args();
@@ -794,7 +796,6 @@ class DrupalWebTestCase {
     default_profile_tasks($task, '');
 
     // Rebuild caches.
-    menu_rebuild();
     actions_synchronize();
     _drupal_flush_css_js();
     $this->refreshVariables();
@@ -813,6 +814,16 @@ class DrupalWebTestCase {
   }
 
   /**
+   * This method is called by DrupalWebTestCase::setUp, and preloads the 
+   * registry from the testing site to cut down on the time it takes to 
+   * setup the a clean environment for the current test run. 
+   */ 
+  protected function preloadRegistry() {
+    db_query('INSERT INTO {registry} SELECT * FROM ' . $this->originalPrefix . 'registry');
+    db_query('INSERT INTO {registry_file} SELECT * FROM ' . $this->originalPrefix . 'registry_file');
+  }
+
+  /**
    * Refresh the in-memory set of variables. Useful after a page request is made
    * that changes a variable in a different thread.
    *
Index: modules/simpletest/tests/registry.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/registry.test,v
retrieving revision 1.4
diff -u -p -r1.4 registry.test
--- modules/simpletest/tests/registry.test	25 Nov 2008 13:14:28 -0000	1.4
+++ modules/simpletest/tests/registry.test	29 Nov 2008 22:45:53 -0000
@@ -22,9 +22,9 @@ class RegistryParseFileTestCase extends 
    * testRegistryParseFile
    */
   function testRegistryParseFile() {
-    _registry_parse_file($this->fileName, $this->getFileContents());
+    _registry_parse_file($this->fileName, $this->getFileContents(), 1);
     foreach (array('functionName', 'className', 'interfaceName') as $resource) {
-      $foundName = db_result(db_query("SELECT name FROM {registry} WHERE name = '%s'", $this->$resource));
+      $foundName = db_result(db_query("SELECT name FROM {registry} WHERE enabled = 1 AND name = '%s'", $this->$resource));
       $this->assertTrue($this->$resource == $foundName, t('Resource "@resource" found.', array('@resource' => $this->$resource)));
     }
   }
@@ -79,7 +79,7 @@ class RegistryParseFilesTestCase extends
 
         // Insert some fake resource records.
         foreach (array('function', 'class', 'interface') as $type) {
-          db_query("INSERT INTO {registry} (name, type, filename) VALUES ('%s', '%s', '%s')", $type . md5(rand()), $type, $this->$fileType->fileName);
+          db_query("INSERT INTO {registry} (name, type, filename, enabled) VALUES ('%s', '%s', '%s', 1)", $type . md5(rand()), $type, $this->$fileType->fileName);
         }
       }
     }
@@ -108,7 +108,7 @@ class RegistryParseFilesTestCase extends
   function getFiles() {
     $files = array();
     foreach ($this->fileTypes as $fileType) {
-      $files[$this->$fileType->fileName] = array('module' => '', 'weight' => 0);
+      $files[$this->$fileType->fileName] = array('module' => '', 'weight' => 0, 'enabled' => 1);
       if ($fileType == 'existing_changed') {
         $files[$this->$fileType->fileName]['md5'] = $this->$fileType->fakeMD5;
       }
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.290
diff -u -p -r1.290 system.install
--- modules/system/system.install	29 Nov 2008 09:33:51 -0000	1.290
+++ modules/system/system.install	29 Nov 2008 22:46:05 -0000
@@ -1096,6 +1096,12 @@ function system_schema() {
         'not null' => TRUE,
         'default' => 0,
       ),
+      'enabled' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+        'size' => 'small',
+      ),
     ),
     'primary key' => array('name', 'type'),
     'indexes' => array(
@@ -3143,6 +3149,15 @@ function system_update_7015() {
 }
 
 /**
+ * Add the enabled column to the {registry} table.
+ */
+function system_update_7016() {
+  $ret = array();
+  db_add_field($ret, 'registry', 'enabled', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+  return $ret;
+}
+
+/**
  * @} End of "defgroup updates-6.x-to-7.x"
  * The next series of updates should start at 8000.
  */
