Index: gtk/gtkcellrenderertext.c
===================================================================
--- gtk/gtkcellrenderertext.c	(revision 18078)
+++ gtk/gtkcellrenderertext.c	(working copy)
@@ -128,6 +128,7 @@
 typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
 struct _GtkCellRendererTextPrivate
 {
+  PangoLayout *layout;
   guint single_paragraph : 1;
   guint language_set : 1;
   guint markup_set : 1;
@@ -170,6 +171,7 @@
   priv->wrap_width = -1;
   priv->align = PANGO_ALIGN_LEFT;
   priv->align_set = FALSE;
+  priv->layout = NULL;
 }
 
 static void
@@ -600,6 +602,9 @@
   if (priv->language)
     g_object_unref (priv->language);
 
+  if (priv->layout)
+    g_object_unref (priv->layout);
+
   (* G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize) (object);
 }
 
@@ -1323,6 +1328,12 @@
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
     }
+    
+    if (priv->layout != NULL)
+      {
+	 g_object_unref (priv->layout);
+	 priv->layout = NULL;
+      }
 }
 
 /**
@@ -1356,9 +1367,7 @@
 
 static PangoLayout*
 get_layout (GtkCellRendererText *celltext,
-            GtkWidget           *widget,
-            gboolean             will_render,
-            GtkCellRendererState flags)
+            GtkWidget           *widget)
 {
   PangoAttrList *attr_list;
   PangoLayout *layout;
@@ -1376,67 +1385,34 @@
 
   pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
 
-  if (will_render)
-    {
-      /* Add options that affect appearance but not size */
-      
-      /* note that background doesn't go here, since it affects
-       * background_area not the PangoLayout area
-       */
-      
-      if (celltext->foreground_set
-	  && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
-        {
-          PangoColor color;
+  if (celltext->strikethrough_set)
+    add_attr (attr_list,
+              pango_attr_strikethrough_new (celltext->strikethrough));
 
-          color = celltext->foreground;
-          
-          add_attr (attr_list,
-                    pango_attr_foreground_new (color.red, color.green, color.blue));
-        }
-
-      if (celltext->strikethrough_set)
-        add_attr (attr_list,
-                  pango_attr_strikethrough_new (celltext->strikethrough));
-    }
-
   add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
 
   if (celltext->scale_set &&
       celltext->font_scale != 1.0)
     add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
+
+  if (priv->language_set)
+    add_attr (attr_list, pango_attr_language_new (priv->language));
   
   if (celltext->underline_set)
     uline = celltext->underline_style;
   else
     uline = PANGO_UNDERLINE_NONE;
-
-  if (priv->language_set)
-    add_attr (attr_list, pango_attr_language_new (priv->language));
   
-  if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
-    {
-      switch (uline)
-        {
-        case PANGO_UNDERLINE_NONE:
-          uline = PANGO_UNDERLINE_SINGLE;
-          break;
-
-        case PANGO_UNDERLINE_SINGLE:
-          uline = PANGO_UNDERLINE_DOUBLE;
-          break;
-
-        default:
-          break;
-        }
-    }
-
   if (uline != PANGO_UNDERLINE_NONE)
     add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
 
   if (celltext->rise_set)
     add_attr (attr_list, pango_attr_rise_new (celltext->rise));
 
+  pango_layout_set_attributes (layout, attr_list);
+
+  pango_attr_list_unref (attr_list);
+  
   if (priv->ellipsize_set)
     pango_layout_set_ellipsize (layout, priv->ellipsize);
   else
@@ -1467,10 +1443,6 @@
       pango_layout_set_alignment (layout, align);
     }
 
-  pango_layout_set_attributes (layout, attr_list);
-
-  pango_attr_list_unref (attr_list);
-  
   return layout;
 }
 
@@ -1478,7 +1450,6 @@
 get_size (GtkCellRenderer *cell,
 	  GtkWidget       *widget,
 	  GdkRectangle    *cell_area,
-	  PangoLayout     *layout,
 	  gint            *x_offset,
 	  gint            *y_offset,
 	  gint            *width,
@@ -1528,13 +1499,11 @@
       if (width == NULL)
 	return;
     }
-  
-  if (layout)
-    g_object_ref (layout);
-  else
-    layout = get_layout (celltext, widget, FALSE, 0);
 
-  pango_layout_get_extents (layout, NULL, &rect);
+  if (priv->layout == NULL)
+    priv->layout = get_layout (celltext, widget);
+
+  pango_layout_get_extents (priv->layout, NULL, &rect);
   pango_extents_to_pixels (&rect, NULL);
 
   if (height)
@@ -1543,13 +1512,13 @@
   /* The minimum size for ellipsized labels is ~ 3 chars */
   if (width)
     {
-      if (priv->ellipsize || priv->width_chars > 0)
+      if (priv->ellipsize_set || priv->width_chars > 0)
 	{
 	  PangoContext *context;
 	  PangoFontMetrics *metrics;
 	  gint char_width;
 
-	  context = pango_layout_get_context (layout);
+	  context = pango_layout_get_context (priv->layout);
 	  metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
 
 	  char_width = pango_font_metrics_get_approximate_char_width (metrics);
@@ -1586,8 +1555,6 @@
       if (x_offset) *x_offset = 0;
       if (y_offset) *y_offset = 0;
     }
-
-  g_object_unref (layout);
 }
 
 
@@ -1600,11 +1567,73 @@
 				 gint            *width,
 				 gint            *height)
 {
-  get_size (cell, widget, cell_area, NULL,
+  get_size (cell, widget, cell_area,
 	    x_offset, y_offset, width, height);
 }
 
 static void
+cell_layout_set_flags (GtkCellRenderer      *cell,
+		       GtkCellRendererState flags)
+{
+  GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
+  PangoAttrList *attr_list;
+  GtkCellRendererTextPrivate *priv;
+  PangoUnderline uline;
+
+  priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
+  g_return_if_fail (priv->layout != NULL);
+  
+  if (flags == 0)
+    return;
+  
+  attr_list = pango_layout_get_attributes (priv->layout);
+  if (attr_list == NULL)
+      attr_list = pango_attr_list_new ();
+  else
+      pango_attr_list_ref (attr_list);
+
+  if (celltext->foreground_set
+      && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
+    {
+      PangoColor color;
+
+      color = celltext->foreground;
+      
+      add_attr (attr_list,
+                pango_attr_foreground_new (color.red, color.green, color.blue));
+    }
+
+  if (celltext->underline_set)
+    uline = celltext->underline_style;
+  else
+    uline = PANGO_UNDERLINE_NONE;
+  
+  if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
+    {
+      switch (uline)
+        {
+        case PANGO_UNDERLINE_NONE:
+          uline = PANGO_UNDERLINE_SINGLE;
+          break;
+
+        case PANGO_UNDERLINE_SINGLE:
+          uline = PANGO_UNDERLINE_DOUBLE;
+          break;
+
+        default:
+          break;
+        }
+      add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
+    }
+
+  pango_layout_set_attributes (priv->layout, attr_list);
+
+  pango_attr_list_unref (attr_list);
+
+  return;  
+}
+
+static void
 gtk_cell_renderer_text_render (GtkCellRenderer      *cell,
 			       GdkDrawable          *window,
 			       GtkWidget            *widget,
@@ -1615,7 +1644,6 @@
 
 {
   GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
-  PangoLayout *layout;
   GtkStateType state;
   gint x_offset;
   gint y_offset;
@@ -1623,9 +1651,17 @@
 
   priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
 
-  layout = get_layout (celltext, widget, TRUE, flags);
-  get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
+  if (priv->layout == NULL);
+     priv->layout = get_layout (celltext, widget);
 
+  if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
+    pango_layout_set_width (priv->layout, 
+			    (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
+
+  cell_layout_set_flags (cell, flags);	 
+
+  get_size (cell, widget, cell_area, &x_offset, &y_offset, NULL, NULL);
+
   if (!cell->sensitive) 
     {
       state = GTK_STATE_INSENSITIVE;
@@ -1671,12 +1707,6 @@
       cairo_destroy (cr);
     }
 
-  if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
-    pango_layout_set_width (layout, 
-			    (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
-  else if (priv->wrap_width == -1)
-    pango_layout_set_width (layout, -1);
-
   gtk_paint_layout (widget->style,
                     window,
                     state,
@@ -1686,9 +1716,7 @@
                     "cellrenderertext",
                     cell_area->x + x_offset + cell->xpad,
                     cell_area->y + y_offset + cell->ypad,
-                    layout);
-
-  g_object_unref (layout);
+                    priv->layout);
 }
 
 static void
