label: Optimize GtkLabel setters

The overarching goal here is to not queue a resize
unless something has actually changed. In columnview
scenarios, we often deal with hundreds of labels.

Labels are cattle, not pets.
This commit is contained in:
Matthias Clasen 2020-11-11 10:35:09 -05:00
parent 5ed3ad6cc8
commit 0db504edde

View File

@ -449,7 +449,7 @@ static gboolean gtk_label_query_tooltip (GtkWidget *widget,
static void gtk_label_set_text_internal (GtkLabel *self,
char *str);
static void gtk_label_set_label_internal (GtkLabel *self,
static gboolean gtk_label_set_label_internal (GtkLabel *self,
char *str);
static gboolean gtk_label_set_use_markup_internal (GtkLabel *self,
gboolean val);
@ -1702,15 +1702,22 @@ gtk_label_set_text_internal (GtkLabel *self,
gtk_label_select_region_index (self, 0, 0);
}
static void
static gboolean
gtk_label_set_label_internal (GtkLabel *self,
char *str)
{
g_free (self->label);
if (g_strcmp0 (str, self->label) == 0)
{
g_free (str);
return FALSE;
}
g_free (self->label);
self->label = str;
g_object_notify_by_pspec (G_OBJECT (self), label_props[PROP_LABEL]);
return TRUE;
}
static gboolean
@ -1802,10 +1809,9 @@ gtk_label_set_text (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (self));
gtk_label_set_label_internal (self, g_strdup (str ? str : ""));
gtk_label_set_use_markup_internal (self, FALSE);
gtk_label_set_use_underline_internal (self, FALSE);
if (gtk_label_set_label_internal (self, g_strdup (str ? str : "")) ||
gtk_label_set_use_markup_internal (self, FALSE) ||
gtk_label_set_use_underline_internal (self, FALSE))
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self));
@ -1888,7 +1894,7 @@ gtk_label_set_label (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (self));
gtk_label_set_label_internal (self, g_strdup (str ? str : ""));
if (gtk_label_set_label_internal (self, g_strdup (str ? str : "")))
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self));
@ -2413,10 +2419,9 @@ gtk_label_set_markup (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (self));
gtk_label_set_label_internal (self, g_strdup (str ? str : ""));
gtk_label_set_use_markup_internal (self, TRUE);
gtk_label_set_use_underline_internal (self, FALSE);
if (gtk_label_set_label_internal (self, g_strdup (str ? str : "")) ||
gtk_label_set_use_markup_internal (self, TRUE) ||
gtk_label_set_use_underline_internal (self, FALSE))
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self));
@ -2445,10 +2450,9 @@ gtk_label_set_markup_with_mnemonic (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (self));
gtk_label_set_label_internal (self, g_strdup (str ? str : ""));
gtk_label_set_use_markup_internal (self, TRUE);
gtk_label_set_use_underline_internal (self, TRUE);
if (gtk_label_set_label_internal (self, g_strdup (str ? str : "")) ||
gtk_label_set_use_markup_internal (self, TRUE) ||
gtk_label_set_use_underline_internal (self, TRUE))
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self));
@ -3568,10 +3572,9 @@ gtk_label_set_text_with_mnemonic (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (self));
gtk_label_set_label_internal (self, g_strdup (str));
gtk_label_set_use_markup_internal (self, FALSE);
gtk_label_set_use_underline_internal (self, TRUE);
if (gtk_label_set_label_internal (self, g_strdup (str)) ||
gtk_label_set_use_markup_internal (self, FALSE) ||
gtk_label_set_use_underline_internal (self, TRUE))
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self));