[libgnome-volume-control/feature/gobject-cleanups: 5/8] mixer-control: Improve GObject properties gunk a bit
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgnome-volume-control/feature/gobject-cleanups: 5/8] mixer-control: Improve GObject properties gunk a bit
- Date: Sun, 29 May 2022 11:47:54 +0000 (UTC)
commit 418f277ae5895083ae1d25dec6dc39cee74ff994
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sun May 29 13:45:12 2022 +0200
mixer-control: Improve GObject properties gunk a bit
Keep track of the `GParamSpec`s of the properties. This allows us to use
`g_object_notify_by_pspec()`, which is a bit more performant than
`g_object_notify()`(as it doesn't need to take a global lock to lookup
the property name). It also prevents accidental typos in the property
name at compile time.
Also always add `G_PARAM_STATIC_STRINGS`, to prevent some unnecessary
string duplications of property name, blurb and description.
gvc-mixer-control.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
---
diff --git a/gvc-mixer-control.c b/gvc-mixer-control.c
index d84da35..ab7aba8 100644
--- a/gvc-mixer-control.c
+++ b/gvc-mixer-control.c
@@ -54,8 +54,10 @@
enum {
PROP_0,
- PROP_NAME
+ PROP_NAME,
+ N_PROPS
};
+static GParamSpec *obj_props[N_PROPS] = { NULL, };
struct GvcMixerControlPrivate
{
@@ -3628,7 +3630,7 @@ gvc_mixer_control_set_property (GObject *object,
case PROP_NAME:
g_free (self->priv->name);
self->priv->name = g_value_dup_string (value);
- g_object_notify (G_OBJECT (self), "name");
+ g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NAME]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -3684,13 +3686,12 @@ gvc_mixer_control_class_init (GvcMixerControlClass *klass)
object_class->set_property = gvc_mixer_control_set_property;
object_class->get_property = gvc_mixer_control_get_property;
- g_object_class_install_property (object_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name to display for this mixer control",
- NULL,
- G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+ obj_props[PROP_NAME] = g_param_spec_string ("name",
+ "Name",
+ "Name to display for this mixer control",
+ NULL,
+
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY|G_PARAM_STATIC_STRINGS);
+ g_object_class_install_properties (object_class, N_PROPS, obj_props);
signals [STATE_CHANGED] =
g_signal_new ("state-changed",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]