[gtk/wip/baedert/for-master] label: Try to avoid a pango_layout_get_extents call
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master] label: Try to avoid a pango_layout_get_extents call
- Date: Sat, 15 Aug 2020 15:07:55 +0000 (UTC)
commit 1fadcb1d44b57f830daeb8e11429c972f6732c32
Author: Timm Bäder <mail baedert org>
Date: Sat Aug 15 17:03:46 2020 +0200
label: Try to avoid a pango_layout_get_extents call
Measuring text is quite expensive, so only do this if really necessary.
gtk/gtklabel.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 1e9f566346..378069d8a5 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -2782,7 +2782,6 @@ gtk_label_get_measuring_layout (GtkLabel *self,
PangoLayout *existing_layout,
int width)
{
- PangoRectangle rect;
PangoLayout *copy;
if (existing_layout != NULL)
@@ -2820,13 +2819,17 @@ gtk_label_get_measuring_layout (GtkLabel *self,
* can just return the current layout, because for measuring purposes, it will be
* identical.
*/
- pango_layout_get_extents (self->layout, NULL, &rect);
- if ((width == -1 || rect.width <= width) &&
- !pango_layout_is_wrapped (self->layout) &&
+ if (!pango_layout_is_wrapped (self->layout) &&
!pango_layout_is_ellipsized (self->layout))
{
- g_object_ref (self->layout);
- return self->layout;
+ PangoRectangle rect;
+
+ if (width == -1)
+ return g_object_ref (self->layout);
+
+ pango_layout_get_extents (self->layout, NULL, &rect);
+ if (rect.width <= width)
+ return g_object_ref (self->layout);
}
copy = pango_layout_copy (self->layout);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]