]> Pileus Git - ~andy/gtk/commitdiff
label: Add optimization for a common special case
authorBenjamin Otte <otte@redhat.com>
Tue, 29 Mar 2011 01:16:34 +0000 (03:16 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 29 Mar 2011 13:33:27 +0000 (15:33 +0200)
Oftentimes we want to measure a layout that is as wide or wider than the
current layout's maximal width. In that case we can safely reuse the
current layout.

gtk/gtklabel.c

index e9601ec1fef1b74176e3e430356ae842e692ad54..d17f4d7eba9fa473104aa123e5f946bc4905936a 100644 (file)
@@ -3044,6 +3044,7 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
                                 int          width)
 {
   GtkLabelPrivate *priv = label->priv;
+  PangoRectangle rect;
   PangoLayout *copy;
 
   if (existing_layout != NULL)
@@ -3065,6 +3066,18 @@ gtk_label_get_measuring_layout (GtkLabel *   label,
       return priv->layout;
     }
 
+  /* oftentimes we want to measure a width that is far wider than the current width,
+   * even though the layout is not wrapped. In that case, we can just return the
+   * current layout, because for measuring purposes, it will be identical.
+   */
+  pango_layout_get_extents (priv->layout, NULL, &rect);
+  if ((width == -1 || rect.width <= width) &&
+      !pango_layout_is_wrapped (priv->layout))
+    {
+      g_object_ref (priv->layout);
+      return priv->layout;
+    }
+
   copy = pango_layout_copy (priv->layout);
   pango_layout_set_width (copy, width);
   return copy;