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, static void gtk_label_set_text_internal (GtkLabel *self,
char *str); char *str);
static void gtk_label_set_label_internal (GtkLabel *self, static gboolean gtk_label_set_label_internal (GtkLabel *self,
char *str); char *str);
static gboolean gtk_label_set_use_markup_internal (GtkLabel *self, static gboolean gtk_label_set_use_markup_internal (GtkLabel *self,
gboolean val); gboolean val);
@ -1702,15 +1702,22 @@ gtk_label_set_text_internal (GtkLabel *self,
gtk_label_select_region_index (self, 0, 0); gtk_label_select_region_index (self, 0, 0);
} }
static void static gboolean
gtk_label_set_label_internal (GtkLabel *self, gtk_label_set_label_internal (GtkLabel *self,
char *str) 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; self->label = str;
g_object_notify_by_pspec (G_OBJECT (self), label_props[PROP_LABEL]); g_object_notify_by_pspec (G_OBJECT (self), label_props[PROP_LABEL]);
return TRUE;
} }
static gboolean static gboolean
@ -1784,7 +1791,7 @@ gtk_label_recalculate (GtkLabel *self)
* @str: The text you want to set * @str: The text you want to set
* *
* Sets the text within the #GtkLabel widget. It overwrites any text that * Sets the text within the #GtkLabel widget. It overwrites any text that
* was there before. * was there before.
* *
* This function will clear any previously set mnemonic accelerators, and * This function will clear any previously set mnemonic accelerators, and
* set the #GtkLabel:use-underline property to %FALSE as a side effect. * set the #GtkLabel:use-underline property to %FALSE as a side effect.
@ -1796,17 +1803,16 @@ gtk_label_recalculate (GtkLabel *self)
**/ **/
void void
gtk_label_set_text (GtkLabel *self, gtk_label_set_text (GtkLabel *self,
const char *str) const char *str)
{ {
g_return_if_fail (GTK_IS_LABEL (self)); g_return_if_fail (GTK_IS_LABEL (self));
g_object_freeze_notify (G_OBJECT (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_set_use_markup_internal (self, FALSE); gtk_label_set_use_markup_internal (self, FALSE) ||
gtk_label_set_use_underline_internal (self, FALSE); gtk_label_set_use_underline_internal (self, FALSE))
gtk_label_recalculate (self);
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self)); g_object_thaw_notify (G_OBJECT (self));
} }
@ -1882,14 +1888,14 @@ gtk_label_get_attributes (GtkLabel *self)
**/ **/
void void
gtk_label_set_label (GtkLabel *self, gtk_label_set_label (GtkLabel *self,
const char *str) const char *str)
{ {
g_return_if_fail (GTK_IS_LABEL (self)); g_return_if_fail (GTK_IS_LABEL (self));
g_object_freeze_notify (G_OBJECT (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); gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self)); g_object_thaw_notify (G_OBJECT (self));
} }
@ -2413,11 +2419,10 @@ gtk_label_set_markup (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (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_set_use_markup_internal (self, TRUE); gtk_label_set_use_markup_internal (self, TRUE) ||
gtk_label_set_use_underline_internal (self, FALSE); gtk_label_set_use_underline_internal (self, FALSE))
gtk_label_recalculate (self);
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self)); g_object_thaw_notify (G_OBJECT (self));
} }
@ -2445,11 +2450,10 @@ gtk_label_set_markup_with_mnemonic (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (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_set_use_markup_internal (self, TRUE); gtk_label_set_use_markup_internal (self, TRUE) ||
gtk_label_set_use_underline_internal (self, TRUE); gtk_label_set_use_underline_internal (self, TRUE))
gtk_label_recalculate (self);
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self)); g_object_thaw_notify (G_OBJECT (self));
} }
@ -3568,11 +3572,10 @@ gtk_label_set_text_with_mnemonic (GtkLabel *self,
g_object_freeze_notify (G_OBJECT (self)); g_object_freeze_notify (G_OBJECT (self));
gtk_label_set_label_internal (self, g_strdup (str)); if (gtk_label_set_label_internal (self, g_strdup (str)) ||
gtk_label_set_use_markup_internal (self, FALSE); gtk_label_set_use_markup_internal (self, FALSE) ||
gtk_label_set_use_underline_internal (self, TRUE); gtk_label_set_use_underline_internal (self, TRUE))
gtk_label_recalculate (self);
gtk_label_recalculate (self);
g_object_thaw_notify (G_OBJECT (self)); g_object_thaw_notify (G_OBJECT (self));
} }
@ -4825,7 +4828,7 @@ gtk_label_get_layout_offsets (GtkLabel *self,
**/ **/
void void
gtk_label_set_use_markup (GtkLabel *self, gtk_label_set_use_markup (GtkLabel *self,
gboolean setting) gboolean setting)
{ {
g_return_if_fail (GTK_IS_LABEL (self)); g_return_if_fail (GTK_IS_LABEL (self));
@ -4865,7 +4868,7 @@ gtk_label_get_use_markup (GtkLabel *self)
*/ */
void void
gtk_label_set_use_underline (GtkLabel *self, gtk_label_set_use_underline (GtkLabel *self,
gboolean setting) gboolean setting)
{ {
g_return_if_fail (GTK_IS_LABEL (self)); g_return_if_fail (GTK_IS_LABEL (self));