Index: install.php
===================================================================
RCS file: /cvs/drupal/drupal/install.php,v
retrieving revision 1.162
diff -u -p -r1.162 install.php
--- install.php	2 Apr 2009 20:39:44 -0000	1.162
+++ install.php	3 Apr 2009 17:33:27 -0000
@@ -53,7 +53,8 @@ function install_main() {
   include_once DRUPAL_ROOT . '/includes/session.inc';
   $module_list['system']['filename'] = 'modules/system/system.module';
   $module_list['filter']['filename'] = 'modules/filter/filter.module';
-  module_list(TRUE, FALSE, $module_list);
+  drupal_static_reset('module_list');
+  module_list(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.279
diff -u -p -r1.279 update.php
--- update.php	9 Mar 2009 20:58:19 -0000	1.279
+++ update.php	3 Apr 2009 17:33:27 -0000
@@ -697,7 +697,8 @@ if (empty($op)) {
   include_once DRUPAL_ROOT . '/includes/module.inc';
   $module_list['system']['filename'] = 'modules/system/system.module';
   $module_list['filter']['filename'] = 'modules/filter/filter.module';
-  module_list(TRUE, FALSE, $module_list);
+  drupal_static_reset('module_list');
+  module_list(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.273
diff -u -p -r1.273 bootstrap.inc
--- includes/bootstrap.inc	2 Apr 2009 20:39:44 -0000	1.273
+++ includes/bootstrap.inc	3 Apr 2009 17:33:28 -0000
@@ -1416,7 +1416,7 @@ function drupal_get_schema($table = NULL
         // "prime" module_list() here to to values we want, specifically
         // "yes rebuild the list and don't limit to bootstrap".
         // TODO: Remove this call after http://drupal.org/node/222109 is fixed.
-        module_list(TRUE);
+        drupal_static_reset('module_list');
         module_load_all_includes('install');
       }
 
Index: includes/mail.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/mail.inc,v
retrieving revision 1.19
diff -u -p -r1.19 mail.inc
--- includes/mail.inc	30 Mar 2009 05:32:31 -0000	1.19
+++ includes/mail.inc	3 Apr 2009 17:33:28 -0000
@@ -260,10 +260,7 @@ function drupal_wrap_mail($text, $indent
  */
 function drupal_html_to_text($string, $allowed_tags = NULL) {
   // Cache list of supported tags.
-  static $supported_tags;
-  if (empty($supported_tags)) {
-    $supported_tags = array('a', 'em', 'i', 'strong', 'b', 'br', 'p', 'blockquote', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr');
-  }
+  $supported_tags = &drupal_static(__FUNCTION__, array('a', 'em', 'i', 'strong', 'b', 'br', 'p', 'blockquote', 'ul', 'ol', 'li', 'dl', 'dt', 'dd', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr'));
 
   // Make sure only supported tags are kept.
   $allowed_tags = isset($allowed_tags) ? array_intersect($supported_tags, $allowed_tags) : $supported_tags;
@@ -278,7 +275,8 @@ function drupal_html_to_text($string, $a
   // Replace inline <a> tags with the text of link and a footnote.
   // 'See <a href="http://drupal.org">the Drupal site</a>' becomes
   // 'See the Drupal site [1]' with the URL included as a footnote.
-  _drupal_html_to_mail_urls(NULL, TRUE);
+  drupal_static_reset('_drupal_html_to_mail_urls');
+  drupal_static_reset('_drupal_html_to_mail_urls:regexp');
   $pattern = '@(<a[^>]+?href="([^"]*)"[^>]*?>(.+?)</a>)@i';
   $string = preg_replace_callback($pattern, '_drupal_html_to_mail_urls', $string);
   $urls = _drupal_html_to_mail_urls();
@@ -434,22 +432,14 @@ function _drupal_wrap_mail_line(&$line, 
  */
 function _drupal_html_to_mail_urls($match = NULL, $reset = FALSE) {
   global $base_url, $base_path;
-  static $urls = array(), $regexp;
+  $urls = &drupal_static(__FUNCTION__, array());
+  $regexp = &drupal_static(__FUNCTION__ . ':regexp', '@^' . preg_quote($base_path, '@') . '@');
 
-  if ($reset) {
-    // Reset internal URL list.
-    $urls = array();
-  }
-  else {
-    if (empty($regexp)) {
-      $regexp = '@^' . preg_quote($base_path, '@') . '@';
-    }
-    if ($match) {
-      list(, , $url, $label) = $match;
-      // Ensure all URLs are absolute.
-      $urls[] = strpos($url, '://') ? $url : preg_replace($regexp, $base_url . '/', $url);
-      return $label . ' [' . count($urls) . ']';
-    }
+  if ($match) {
+    list(, , $url, $label) = $match;
+    // Ensure all URLs are absolute.
+    $urls[] = strpos($url, '://') ? $url : preg_replace($regexp, $base_url . '/', $url);
+    return $label . ' [' . count($urls) . ']';
   }
   return $urls;
 }
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.139
diff -u -p -r1.139 module.inc
--- includes/module.inc	22 Feb 2009 17:55:29 -0000	1.139
+++ includes/module.inc	3 Apr 2009 17:33:28 -0000
@@ -21,7 +21,8 @@ define('MODULE_IMPLEMENTS_CLEAR_CACHE', 
  * Load all the modules that have been enabled in the system table.
  */
 function module_load_all() {
-  foreach (module_list(TRUE) as $module) {
+  drupal_static_reset('module_list');
+  foreach (module_list() as $module) {
     drupal_load('module', $module);
   }
 }
@@ -43,10 +44,11 @@ function module_load_all() {
  *   An associative array whose keys and values are the names of all loaded
  *   modules.
  */
-function module_list($refresh = FALSE, $sort = FALSE, $fixed_list = NULL) {
-  static $list = array(), $sorted_list;
+function module_list($sort = FALSE, $fixed_list = NULL) {
+  $list = &drupal_static(__FUNCTION__, array());
+  $sorted_list = &drupal_static(__FUNCTION__ . ':sorted_list');
 
-  if (empty($list) || $refresh || $fixed_list) {
+  if (empty($list) || $fixed_list) {
     $list = array();
     $sorted_list = NULL;
     if ($fixed_list) {
@@ -263,7 +265,7 @@ function module_enable($module_list) {
 
   if (!empty($invoke_modules)) {
     // Refresh the module list to include the new enabled module.
-    module_list(TRUE);
+    drupal_static_reset('module_list');
     // Force to regenerate the stored list of hook implementations.
     registry_rebuild();
   }
@@ -317,7 +319,7 @@ function module_disable($module_list) {
     // so we can still call module hooks to get information.
     module_invoke_all('modules_disabled', $invoke_modules);
     // Refresh the module list to exclude the disabled modules.
-    module_list(TRUE);
+    drupal_static_reset('module_list');
     // Force to regenerate the stored list of hook implementations.
     registry_rebuild();
   }
@@ -390,7 +392,10 @@ function module_hook($module, $hook) {
  *   the implementations are loaded as necessary.
  */
 function module_implements($hook, $sort = FALSE) {
-  static $implementations = array(), $sorted_implementations = array(), $loaded = array(), $cached_hooks = 0;
+  $implementations = &drupal_static(__FUNCTION__, array());
+  $sorted_implementations = &drupal_static(__FUNCTION__ . ':sorted_implementations', array());
+  $loaded = &drupal_static(__FUNCTION__ . ':loaded', array());
+  $cached_hooks = &drupal_static(__FUNCTION__ . ':cached_hooks', 0);
 
   if (defined('MAINTENANCE_MODE')) {
     return _module_implements_maintenance($hook, $sort);
Index: includes/pager.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/pager.inc,v
retrieving revision 1.65
diff -u -p -r1.65 pager.inc
--- includes/pager.inc	22 Feb 2009 16:53:41 -0000	1.65
+++ includes/pager.inc	3 Apr 2009 17:33:28 -0000
@@ -227,10 +227,7 @@ function pager_query($query, $limit = 10
  *   except for those pertaining to paging.
  */
 function pager_get_querystring() {
-  static $string = NULL;
-  if (!isset($string)) {
-    $string = drupal_query_string_encode($_REQUEST, array_merge(array('q', 'page'), array_keys($_COOKIE)));
-  }
+  $string = &drupal_static(__FUNCTION__, drupal_query_string_encode($_REQUEST, array_merge(array('q', 'page'), array_keys($_COOKIE))));
   return $string;
 }
 
@@ -533,15 +530,12 @@ function theme_pager_link($text, $page_n
 
   // Set each pager link title
   if (!isset($attributes['title'])) {
-    static $titles = NULL;
-    if (!isset($titles)) {
-      $titles = array(
+    $titles = &drupal_static(__FUNCTION__, array(
         t('« first') => t('Go to first page'),
         t('‹ previous') => t('Go to previous page'),
         t('next ›') => t('Go to next page'),
         t('last »') => t('Go to last page'),
-      );
-    }
+      ));
     if (isset($titles[$text])) {
       $attributes['title'] = $titles[$text];
     }
Index: includes/theme.maintenance.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/theme.maintenance.inc,v
retrieving revision 1.21
diff -u -p -r1.21 theme.maintenance.inc
--- includes/theme.maintenance.inc	24 Nov 2008 10:41:39 -0000	1.21
+++ includes/theme.maintenance.inc	3 Apr 2009 17:33:28 -0000
@@ -39,7 +39,8 @@ 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, $module_list);
+    drupal_static_reset('module_list');
+    module_list(FALSE, $module_list);
     drupal_load('module', 'system');
     drupal_load('module', 'filter');
 
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.92
diff -u -p -r1.92 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	30 Mar 2009 05:35:35 -0000	1.92
+++ modules/simpletest/drupal_web_test_case.php	3 Apr 2009 17:33:28 -0000
@@ -924,7 +924,7 @@ class DrupalWebTestCase {
 
       // Reload module list and implementations to ensure that test module hooks
       // aren't called after tests.
-      module_list(TRUE);
+      drupal_static_reset('module_list');
       module_implements(MODULE_IMPLEMENTS_CLEAR_CACHE);
 
       // Reset the Field API.
Index: modules/simpletest/tests/module.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/module.test,v
retrieving revision 1.2
diff -u -p -r1.2 module.test
--- modules/simpletest/tests/module.test	31 Mar 2009 01:49:53 -0000	1.2
+++ modules/simpletest/tests/module.test	3 Apr 2009 17:33:28 -0000
@@ -39,7 +39,7 @@ class ModuleUnitTest extends DrupalWebTe
     // Try to mess with the module weights.
     db_query("UPDATE {system} SET weight = 20 WHERE name = 'path' AND type = 'module'");
     // Reset the module list.
-    module_list(TRUE);
+    drupal_static_reset('module_list');
     // Move path at the end of the array.
     unset($base_module_list['path']);
     $base_module_list['path'] = 'path';
@@ -50,12 +50,12 @@ class ModuleUnitTest extends DrupalWebTe
       'system' => array('filename' => drupal_get_path('module', 'system')),
       'menu' => array('filename' => drupal_get_path('module', 'menu')),
     );
-    module_list(FALSE, FALSE, $fixed_list);
+    module_list(FALSE, $fixed_list);
     $new_module_list = array_combine(array_keys($fixed_list), array_keys($fixed_list));
     $this->assertModuleList($new_module_list, t('When using a fixed list'));
 
     // Reset the module list.
-    module_list(TRUE);
+    drupal_static_reset('module_list');
     $this->assertModuleList($base_module_list, t('After reset'));
   }
 
@@ -68,6 +68,6 @@ class ModuleUnitTest extends DrupalWebTe
   protected function assertModuleList(Array $expected_values, $condition) {
     $this->assertIdentical($expected_values, module_list(), t('@condition: module_list() returns correct results', array('@condition' => $condition)));
     ksort($expected_values);
-    $this->assertIdentical($expected_values, module_list(FALSE, TRUE), t('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
+    $this->assertIdentical($expected_values, module_list(TRUE), t('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
   }
 }
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.131
diff -u -p -r1.131 system.admin.inc
--- modules/system/system.admin.inc	17 Mar 2009 15:26:29 -0000	1.131
+++ modules/system/system.admin.inc	3 Apr 2009 17:33:28 -0000
@@ -922,7 +922,8 @@ function system_modules_submit($form, &$
     drupal_install_modules($new_modules);
   }
 
-  $current_module_list = module_list(TRUE);
+  drupal_static_reset('module_list');
+  $current_module_list = module_list();
   if ($old_module_list != $current_module_list) {
     drupal_set_message(t('The configuration options have been saved.'));
   }
Index: modules/system/system.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.test,v
retrieving revision 1.40
diff -u -p -r1.40 system.test
--- modules/system/system.test	31 Mar 2009 01:49:54 -0000	1.40
+++ modules/system/system.test	3 Apr 2009 17:33:28 -0000
@@ -41,7 +41,7 @@ class ModuleTestCase extends DrupalWebTe
    *   Expected module state.
    */
   function assertModules(array $modules, $enabled) {
-    module_list(TRUE);
+    drupal_static_reset('module_list');
     foreach ($modules as $module) {
       if ($enabled) {
         $message = 'Module "@module" is enabled.';
