[gnome-shell/wip/nielsdg/g-object-notify: 2/4] st-label: Use g_object_notify_by_pspec()
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/nielsdg/g-object-notify: 2/4] st-label: Use g_object_notify_by_pspec()
- Date: Wed, 31 Jul 2019 06:28:20 +0000 (UTC)
commit f86411d2fb2bdd0d90fd41a4824d32dfa5e1b52c
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue Jul 30 22:08:18 2019 +0200
st-label: Use g_object_notify_by_pspec()
`g_object_notify()` actually takes a global lock to look up the property
by its name, which means there is a performance hit (albeit tiny) every
time this function is called. For this reason, always try to use
`g_object_notify_by_pspec()` instead.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/652
src/st/st-label.c | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
---
diff --git a/src/st/st-label.c b/src/st/st-label.c
index ab05087d8..64127c964 100644
--- a/src/st/st-label.c
+++ b/src/st/st-label.c
@@ -51,9 +51,13 @@ enum
PROP_0,
PROP_CLUTTER_TEXT,
- PROP_TEXT
+ PROP_TEXT,
+
+ N_PROPS
};
+static GParamSpec *props[N_PROPS] = { NULL, };
+
struct _StLabelPrivate
{
ClutterActor *label;
@@ -249,7 +253,6 @@ st_label_class_init (StLabelClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
- GParamSpec *pspec;
gobject_class->set_property = st_label_set_property;
gobject_class->get_property = st_label_get_property;
@@ -264,20 +267,21 @@ st_label_class_init (StLabelClass *klass)
widget_class->resource_scale_changed = st_label_resource_scale_changed;
widget_class->get_accessible_type = st_label_accessible_get_type;
- pspec = g_param_spec_object ("clutter-text",
- "Clutter Text",
- "Internal ClutterText actor",
- CLUTTER_TYPE_TEXT,
- ST_PARAM_READABLE);
- g_object_class_install_property (gobject_class, PROP_CLUTTER_TEXT, pspec);
-
- pspec = g_param_spec_string ("text",
- "Text",
- "Text of the label",
- NULL,
- ST_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_TEXT, pspec);
-
+ props[PROP_CLUTTER_TEXT] =
+ g_param_spec_object ("clutter-text",
+ "Clutter Text",
+ "Internal ClutterText actor",
+ CLUTTER_TYPE_TEXT,
+ ST_PARAM_READABLE);
+
+ props[PROP_TEXT] =
+ g_param_spec_string ("text",
+ "Text",
+ "Text of the label",
+ NULL,
+ ST_PARAM_READWRITE);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, props);
}
static void
@@ -359,7 +363,7 @@ st_label_set_text (StLabel *label,
clutter_text_set_text (ctext, text);
- g_object_notify (G_OBJECT (label), "text");
+ g_object_notify_by_pspec (G_OBJECT (label), props[PROP_TEXT]);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]