Index: role_weights.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/role_weights/role_weights.module,v
retrieving revision 1.12.2.1
diff -u -p -r1.12.2.1 role_weights.module
--- role_weights.module	8 Nov 2007 21:18:28 -0000	1.12.2.1
+++ role_weights.module	15 Jan 2008 23:19:23 -0000
@@ -155,13 +155,21 @@ function role_weights_admin_role_submit(
 /**
  * Returns a weight for a given role rid.
  *
- * @param   $role_id
+ * @param $role_id
  *   A role rid
+ * @param $refresh
+ *   If true, the static cache will be refreshed (used if you want to change
+ *   the weight in the midst of a page load). This is done automatically by
+ *   _role_weights_set_weight() - you should not need to do this.
  * @return
  *   A corresponding weight for the role
  */
-function role_weights_get_weight($role_id) {
-  $weights = _role_weights_get_weights();
+function role_weights_get_weight($role_id = NULL, $refresh = FALSE) {
+  // Static cache the weights, to improve performance
+  static $weights;
+  if (!$weights || $refresh) {
+    $weights = _role_weights_get_weights();
+  }
   return $weights[$role_id];
 }
 
@@ -200,6 +208,8 @@ function _role_weights_set_weight($rid, 
   else {
     db_query('INSERT INTO {role_weights} (rid, weight) VALUES (%d, %d)', $rid, $weight);
   }
+  // Force role_weights_get_weight to refresh it's static cache
+  role_weights_get_weight(NULL, TRUE);
 }
 
 /**
