Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.951
diff -u -p -r1.951 common.inc
--- includes/common.inc	31 Jul 2009 19:56:09 -0000	1.951
+++ includes/common.inc	1 Aug 2009 17:14:57 -0000
@@ -1900,20 +1900,31 @@ function format_interval($timestamp, $gr
  *   A translated date string in the requested format.
  */
 function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
-  $timezones = &drupal_static(__FUNCTION__, array());
+  $cache = &drupal_static(__FUNCTION__, array());
+
+  // Maintain a local cache of date variables to avoid repeated calls to
+  // variable_get().
+  if (!isset($cache['variables'])){
+    $cache['variables']['small'] = variable_get('date_format_short', 'm/d/Y - H:i');
+    $cache['variables']['medium'] = variable_get('date_format_medium', 'D, m/d/Y - H:i');
+    $cache['variables']['large'] = variable_get('date_format_long', 'l, F j, Y - H:i');
+    $cache['variables']['configurable_timezones'] = variable_get('configurable_timezones', 1);
+    $cache['variables']['default_timezone'] = variable_get('date_default_timezone', 'UTC');
+  }
+
   if (!isset($timezone)) {
     global $user;
-    if (variable_get('configurable_timezones', 1) && $user->uid && $user->timezone) {
+    if ($user->uid && !empty($cache['variables']['configurable_timezones']) && $user->timezone) {
       $timezone = $user->timezone;
     }
     else {
-      $timezone = variable_get('date_default_timezone', 'UTC');
+      $timezone = $cache['variables']['default_timezone'];
     }
   }
   // Store DateTimeZone objects in an array rather than repeatedly
   // contructing identical objects over the life of a request.
-  if (!isset($timezones[$timezone])) {
-    $timezones[$timezone] = timezone_open($timezone);
+  if (!isset($cache['timezones'][$timezone])) {
+    $cache['timezones'][$timezone] = timezone_open($timezone);
   }
 
   // Use the default langcode if none is set.
@@ -1924,23 +1935,23 @@ function format_date($timestamp, $type =
 
   switch ($type) {
     case 'small':
-      $format = variable_get('date_format_short', 'm/d/Y - H:i');
+      $format = $cache['variables']['small'];
       break;
     case 'large':
-      $format = variable_get('date_format_long', 'l, F j, Y - H:i');
+      $format = $cache['variables']['large'];
       break;
     case 'custom':
       // No change to format.
       break;
     case 'medium':
     default:
-      $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
+      $format = $cache['variables']['medium'];
   }
 
   // Create a DateTime object from the timestamp.
   $date_time = date_create('@' . $timestamp);
   // Set the time zone for the DateTime object.
-  date_timezone_set($date_time, $timezones[$timezone]);
+  date_timezone_set($date_time, $cache['timezones'][$timezone]);
 
   // Encode markers that should be translated. 'A' becomes '\xEF\AA\xFF'.
   // xEF and xFF are invalid UTF-8 sequences, and we assume they are not in the
