Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.973
diff -u -p -r1.973 user.module
--- modules/user/user.module	1 Apr 2009 20:00:47 -0000	1.973
+++ modules/user/user.module	4 Apr 2009 22:40:46 -0000
@@ -171,9 +171,6 @@ function user_external_login($account, $
  * @param $conditions
  *   An array of conditions to match against the {users} table. These
  *   should be supplied in the form array('field_name' => 'field_value').
- * @param $reset
- *   A boolean indicating that the internal cache should be reset. Use this if
- *   loading a user object which has been altered during the page request.
  * @return
  *   An array of user objects, indexed by uid.
  *
@@ -181,11 +178,8 @@ function user_external_login($account, $
  * @see user_load_by_mail()
  * @see user_load_by_name()
  */
-function user_load_multiple($uids = array(), $conditions = array(), $reset = FALSE) {
-  static $user_cache = array();
-  if ($reset) {
-    $user_cache = array();
-  }
+function user_load_multiple($uids = array(), $conditions = array()) {
+  $user_cache = &drupal_static(__FUNCTION__, array());
 
   $users = array();
 
@@ -301,16 +295,14 @@ function user_load_multiple($uids = arra
  *
  * @param $uid
  *   Integer specifying the user id.
- * @param $reset
- *   A boolean indicating that the internal cache should be reset.
  * @return
  *   A fully-loaded $user object upon successful user load or FALSE if user
  *   cannot be loaded.
  *
  * @see user_load_multiple()
  */
-function user_load($uid, $reset = FALSE) {
-  $users = user_load_multiple(array($uid), array(), $reset);
+function user_load($uid) {
+  $users = user_load_multiple(array($uid), array());
   return reset($users);
 }
 
@@ -487,7 +479,8 @@ function user_save($account, $edit = arr
     field_attach_update('user', $object);
 
     // Refresh user object.
-    $user = user_load($account->uid, TRUE);
+    drupal_static_reset('user_multiple_load');
+    $user = user_load($account->uid);
 
     // Send emails after we have the new user object.
     if (isset($edit['status']) && $edit['status'] != $account->status) {
@@ -517,7 +510,8 @@ function user_save($account, $edit = arr
     }
 
     // Build the initial user object.
-    $user = user_load($edit['uid'], TRUE);
+    drupal_static_reset('user_multiple_load');
+    $user = user_load($edit['uid']);
 
     $object = (object) $edit;
     field_attach_insert('user', $object);
@@ -551,7 +545,8 @@ function user_save($account, $edit = arr
     }
 
     // Build the finished user object.
-    $user = user_load($edit['uid'], TRUE);
+    drupal_static_reset('user_multiple_load');
+    $user = user_load($edit['uid']);
   }
 
   return $user;
@@ -652,20 +647,13 @@ function user_password($length = 10) {
  *
  * @param $roles
  *   An array whose keys are the role IDs of interest, such as $user->roles.
- * @param $reset
- *   Optional parameter - if TRUE data in the static variable is rebuilt.
  *
  * @return
  *   An array indexed by role ID. Each value is an array whose keys are the
  *   permission strings for the given role ID.
  */
-function user_role_permissions($roles = array(), $reset = FALSE) {
-  static $stored_permissions = array();
-
-  if ($reset) {
-    // Clear the data cached in the static variable.
-    $stored_permissions = array();
-  }
+function user_role_permissions($roles = array()) {
+  $stored_permissions = &drupal_static(__FUNCTION__, array());
 
   $role_permissions = $fetch = array();
 
@@ -707,10 +695,6 @@ function user_role_permissions($roles = 
  *   The permission, such as "administer nodes", being checked for.
  * @param $account
  *   (optional) The account to check, if not given use currently logged in user.
- * @param $reset
- *   (optional) Resets the user's permissions cache, which will result in a
- *   recalculation of the user's permissions. This is necessary to support
- *   dynamically added user roles.
  *
  * @return
  *   Boolean TRUE if the current user has the requested permission.
@@ -719,13 +703,9 @@ function user_role_permissions($roles = 
  * way, we guarantee consistent behavior, and ensure that the superuser
  * can perform all actions.
  */
-function user_access($string, $account = NULL, $reset = FALSE) {
+function user_access($string, $account = NULL) {
   global $user;
-  static $perm = array();
-
-  if ($reset) {
-    $perm = array();
-  }
+  $perm = &drupal_static(__FUNCTION__, array());
 
   if (is_null($account)) {
     $account = $user;
@@ -739,7 +719,7 @@ function user_access($string, $account =
   // To reduce the number of SQL queries, we cache the user's permissions
   // in a static variable.
   if (!isset($perm[$account->uid])) {
-    $role_permissions = user_role_permissions($account->roles, $reset);
+    $role_permissions = user_role_permissions($account->roles);
 
     $perms = array();
     foreach ($role_permissions as $one_role) {
@@ -1437,7 +1417,8 @@ function user_uid_optional_load($arg) {
  * Return a user object after checking if any profile category in the path exists.
  */
 function user_category_load($uid, &$map, $index) {
-  static $user_categories, $accounts;
+  $user_categories = &drupal_static(__FUNCTION__ . ':categories');
+  $accounts = &drupal_static(__FUNCTION__ . ':accounts', array());
 
   // Cache $account - this load function will get called for each profile tab.
   if (!isset($accounts[$uid])) {
@@ -2613,7 +2594,7 @@ function _user_mail_notify($op, $account
  * strings that need to be passed to the javascript code.
  */
 function _user_password_dynamic_validation() {
-  static $complete = FALSE;
+  $complete = &drupal_static(__FUNCTION__, FALSE);
   global $user;
   // Only need to do once per page.
   if (!$complete) {
Index: modules/user/user.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.test,v
retrieving revision 1.33
diff -u -p -r1.33 user.test
--- modules/user/user.test	31 Mar 2009 01:49:55 -0000	1.33
+++ modules/user/user.test	4 Apr 2009 22:40:46 -0000
@@ -742,12 +742,14 @@ class UserPermissionsTestCase extends Dr
     $account = $this->admin_user;
 
     // Add a permission.
-    $this->assertFalse(user_access('administer nodes', $account, TRUE), t('User does not have "administer nodes" permission.'));
+    drupal_static_reset('user_role_permissions');
+    $this->assertFalse(user_access('administer nodes', $account), t('User does not have "administer nodes" permission.'));
     $edit = array();
     $edit[$rid . '[administer nodes]'] = TRUE;
     $this->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
     $this->assertText(t('The changes have been saved.'), t('Successful save message displayed.'));
-    $this->assertTrue(user_access('administer nodes', $account, TRUE), t('User now has "administer nodes" permission.'));
+    drupal_static_reset('user_role_permissions');
+    $this->assertTrue(user_access('administer nodes', $account), t('User now has "administer nodes" permission.'));
 
     // Remove a permission.
     $this->assertTrue(user_access('access user profiles', $account, TRUE), t('User has "access user profiles" permission.'));
