Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.320
diff -u -r1.320 bootstrap.inc
--- includes/bootstrap.inc	2 Nov 2009 03:46:43 -0000	1.320
+++ includes/bootstrap.inc	2 Nov 2009 15:09:50 -0000
@@ -2010,6 +2010,17 @@
 /**
  * Central static variable storage.
  *
+ * @return
+ *   Returns a variable by reference.
+ */
+function &_drupal_static() {
+  static $data = array();
+  return $data;
+}
+
+/**
+ * Get a centrally stored static variable.
+ *
  * @param $name
  *   Globally unique name for the variable. For a function with only one static,
  *   variable, the function name (e.g. via the PHP magic __FUNCTION__ constant)
@@ -2017,30 +2028,12 @@
  *   distinguishing suffix to the function name for each one.
  * @param $default_value
  *   Optional default value.
- * @param $reset
- *   TRUE to reset a specific named variable, or all variables if $name is NULL.
- *   Resetting every variable should only be used, for example, for running
- *   unit tests with a clean environment. Should be used only though via
- *   function drupal_static_reset().
  *
  * @return
- *   Returns a variable by reference if $reset is FALSE.
+ *   Returns a variable by reference.
  */
-function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
-  static $data = array();
-
-  // Reset a single value, or all values.
-  if ($reset) {
-    if (isset($name)) {
-      unset($data[$name]);
-    }
-    else {
-      $data = array();
-    }
-    // We must return a reference to a variable.
-    $dummy = NULL;
-    return $dummy;
-  }
+function &drupal_static($name, $default_value = NULL) {
+  $data = &_drupal_static();
 
   if (!isset($data[$name])) {
     $data[$name] = $default_value;
@@ -2050,13 +2043,40 @@
 }
 
 /**
+ * Assign a reference to a centrally stored static variable.
+ *
+ * @param $name
+ *   Globally unique name for the variable. For a function with only one static,
+ *   variable, the function name (e.g. via the PHP magic __FUNCTION__ constant)
+ *   is recommended. For a function with multiple static variables add a
+ *   distinguishing suffix to the function name for each one.
+ * @param $reference
+ *   Reference to store.
+ */
+function drupal_static_assign($name, &$reference) {
+  $data = &_drupal_static();
+  $data[$name] = &$reference;
+}
+
+/**
  * Reset one or all centrally stored static variable(s).
  *
  * @param $name
  *   Name of the static variable to reset. Omit to reset all variables.
  */
 function drupal_static_reset($name = NULL) {
-  drupal_static($name, NULL, TRUE);
+  $data = &_drupal_static();
+
+  if (isset($name)) {
+    $data[$name] = NULL; // Set data to NULL
+    unset($data[$name]); // Remove reference
+  }
+  else {
+    foreach (array_keys($data) as $name) {
+      $data[$name] = NULL; // Set data to NULL
+    }
+    $data = array();
+  }
 }
 
 /**
Index: includes/module.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/module.inc,v
retrieving revision 1.164
diff -u -r1.164 module.inc
--- includes/module.inc	1 Nov 2009 22:10:07 -0000	1.164
+++ includes/module.inc	2 Nov 2009 15:09:50 -0000
@@ -367,7 +367,11 @@
  * @see module_implements_write_cache().
  */
 function module_implements($hook, $sort = FALSE, $reset = FALSE) {
-  $implementations = &drupal_static(__FUNCTION__, array());
+  static $implementations;
+  if (!isset($implementations)) {
+    $implementations = array();
+    drupal_static_assign(__FUNCTION__, $implementations);
+  }
 
   // We maintain a persistent cache of hook implementations in addition to the
   // static cache to avoid looping through every module and every hook on each
