Index: modules/comment/comment.module
===================================================================
RCS file: /Users/wright/drupal/local_repo/drupal/modules/comment/comment.module,v
retrieving revision 1.796
diff -u -p -r1.796 comment.module
--- modules/comment/comment.module	23 Oct 2009 22:24:12 -0000	1.796
+++ modules/comment/comment.module	28 Oct 2009 08:25:25 -0000
@@ -2188,10 +2188,16 @@ function theme_comment_post_forbidden($v
   $node = $variables['node'];
   global $user;
 
+  // Since this expensive to compute, we cache it so that a page with many
+  // comments only has to query the database once for all the links.
+  $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);
+
   if (!$user->uid) {
-    // We only output any link if we are certain, that users get permission
-    // to post comments by logging in. We also locally cache this information.
-    $authenticated_post_comments = &drupal_static(__FUNCTION__, array_key_exists(DRUPAL_AUTHENTICATED_RID, user_roles(TRUE, 'post comments') + user_roles(TRUE, 'post comments without approval')));
+    if (!isset($authenticated_post_comments)) {
+      // We only output any link if we are certain that users get permission
+      // to post comments by logging in.
+      $authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, user_roles(TRUE, 'post comments') + user_roles(TRUE, 'post comments without approval'));
+    }
 
     if ($authenticated_post_comments) {
       // We cannot use drupal_get_destination() because these links
