Index: modules/field/modules/text/text.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v
retrieving revision 1.7
diff -u -p -r1.7 text.module
--- modules/field/modules/text/text.module	20 May 2009 09:48:47 -0000	1.7
+++ modules/field/modules/text/text.module	26 May 2009 17:04:23 -0000
@@ -110,18 +110,51 @@ function text_field_validate($obj_type, 
   }
 }
 
+/**
+ * Implementation of hook_field_load().
+ *
+ * Where possible, generate the sanitized version of each field early so that
+ * it is cached in the field cache. This avoids looking up from the filter cache
+ * separately.
+ */
+function text_field_load($obj_type, $objects, $field, $instances, &$items) {
+  global $language;
+  foreach ($objects as $id => $object) {
+    foreach ($items[$id] as $delta => $item) {
+      // TODO D7 : this code is really node-related.
+      if (!empty($instances[$id]['settings']['text_processing'])) {
+        $check = is_null($object) || (isset($object->build_mode) && $object->build_mode == NODE_BUILD_PREVIEW);
+        if (filter_format_allowcache($item['format'])) {
+          $text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language->language, $check, FALSE) : '';
+        }
+      }
+      else {
+        $text = check_plain($item['value']);
+      }
+      if (isset($text)) {
+        $items[$id][$delta]['safe'] = $text;
+      }
+    }
+  }
+}
+
+/**
+ * Implementation of hook_field_sanitize().
+ */
 function text_field_sanitize($obj_type, $object, $field, $instance, &$items) {
   global $language;
   foreach ($items as $delta => $item) {
-    // TODO D7 : this code is really node-related.
-    if (!empty($instance['settings']['text_processing'])) {
-      $check = is_null($object) || (isset($object->build_mode) && $object->build_mode == NODE_BUILD_PREVIEW);
-      $text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language->language, $check) : '';
-    }
-    else {
-      $text = check_plain($item['value']);
-    }
+    if (!isset($items[$delta]['safe'])) {
+      // TODO D7 : this code is really node-related.
+      if (!empty($instance['settings']['text_processing'])) {
+        $check = is_null($object) || (isset($object->build_mode) && $object->build_mode == NODE_BUILD_PREVIEW);
+        $text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language->language, $check) : '';
+      }
+      else {
+        $text = check_plain($item['value']);
+      }
     $items[$delta]['safe'] = $text;
+    }
   }
 }
 
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.255
diff -u -p -r1.255 filter.module
--- modules/filter/filter.module	24 May 2009 19:12:12 -0000	1.255
+++ modules/filter/filter.module	26 May 2009 17:04:23 -0000
@@ -423,15 +423,19 @@ function filter_list_format($format) {
  *    should specify $check = FALSE when viewing other people's content. When
  *    showing content that is not (yet) stored in the database (eg. upon preview),
  *    set to TRUE so the user's permissions are checked.
+ * @param $cache
+ *    Whether to cache the results of this function in the {cache_filter} table.
+ *    If you are caching the results of check_markup() elsewhere you may want
+ *    to set this to FALSE to avoid storing the same data twice.
  */
-function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $langcode = '', $check = TRUE) {
+function check_markup($text, $format = FILTER_FORMAT_DEFAULT, $langcode = '', $check = TRUE, $cache = TRUE) {
   // When $check = TRUE, do an access check on $format.
   if (isset($text) && (!$check || filter_access($format))) {
     $format = filter_resolve_format($format);
 
     // Check for a cached version of this piece of text.
     $cache_id = $format . ':' . $langcode . ':' . md5($text);
-    if ($cached = cache_get($cache_id, 'cache_filter')) {
+    if ($cache && $cached = cache_get($cache_id, 'cache_filter')) {
       return $cached->data;
     }
 
@@ -453,7 +457,7 @@ function check_markup($text, $format = F
     }
 
     // Store in cache with a minimum expiration time of 1 day.
-    if (filter_format_allowcache($format)) {
+    if ($cache && filter_format_allowcache($format)) {
       cache_set($cache_id, $text, 'cache_filter', REQUEST_TIME + (60 * 60 * 24));
     }
   }
