[gnome-shell/wip/nielsdg/g-object-notify: 3/4] st-button: 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: 3/4] st-button: Use g_object_notify_by_pspec()
- Date: Wed, 31 Jul 2019 06:07:26 +0000 (UTC)
commit 2dc2faa5a2747e1081b427f6d89f7eae9398191f
Author: Niels De Graef <nielsdegraef gmail com>
Date: Wed Jul 31 07:32:21 2019 +0200
st-button: 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-button.c | 87 +++++++++++++++++++++++++++++-------------------------
1 file changed, 46 insertions(+), 41 deletions(-)
---
diff --git a/src/st/st-button.c b/src/st/st-button.c
index 3af1811f7..681205e81 100644
--- a/src/st/st-button.c
+++ b/src/st/st-button.c
@@ -54,9 +54,13 @@ enum
PROP_BUTTON_MASK,
PROP_TOGGLE_MODE,
PROP_CHECKED,
- PROP_PRESSED
+ PROP_PRESSED,
+
+ N_PROPS
};
+static GParamSpec *props[N_PROPS] = { NULL, };
+
enum
{
CLICKED,
@@ -476,41 +480,42 @@ st_button_class_init (StButtonClass *klass)
widget_class->style_changed = st_button_style_changed;
widget_class->get_accessible_type = st_button_accessible_get_type;
- pspec = g_param_spec_string ("label",
- "Label",
- "Label of the button",
- NULL,
- ST_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_LABEL, pspec);
-
- pspec = g_param_spec_flags ("button-mask",
- "Button mask",
- "Which buttons trigger the 'clicked' signal",
- ST_TYPE_BUTTON_MASK, ST_BUTTON_ONE,
- ST_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_BUTTON_MASK, pspec);
-
- pspec = g_param_spec_boolean ("toggle-mode",
- "Toggle Mode",
- "Enable or disable toggling",
- FALSE,
- ST_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_TOGGLE_MODE, pspec);
-
- pspec = g_param_spec_boolean ("checked",
- "Checked",
- "Indicates if a toggle button is \"on\""
- " or \"off\"",
- FALSE,
- ST_PARAM_READWRITE);
- g_object_class_install_property (gobject_class, PROP_CHECKED, pspec);
-
- pspec = g_param_spec_boolean ("pressed",
- "Pressed",
- "Indicates if the button is pressed in",
- FALSE,
- ST_PARAM_READABLE);
- g_object_class_install_property (gobject_class, PROP_PRESSED, pspec);
+ props[PROP_LABEL] =
+ g_param_spec_string ("label",
+ "Label",
+ "Label of the button",
+ NULL,
+ ST_PARAM_READWRITE);
+
+ props[PROP_BUTTON_MASK] =
+ g_param_spec_flags ("button-mask",
+ "Button mask",
+ "Which buttons trigger the 'clicked' signal",
+ ST_TYPE_BUTTON_MASK, ST_BUTTON_ONE,
+ ST_PARAM_READWRITE);
+
+ props[PROP_TOGGLE_MODE] =
+ g_param_spec_boolean ("toggle-mode",
+ "Toggle Mode",
+ "Enable or disable toggling",
+ FALSE,
+ ST_PARAM_READWRITE);
+
+ props[PROP_CHECKED] =
+ g_param_spec_boolean ("checked",
+ "Checked",
+ "Indicates if a toggle button is \"on\" or \"off\"",
+ FALSE,
+ ST_PARAM_READWRITE);
+
+ props[PROP_PRESSED] =
+ g_param_spec_boolean ("pressed",
+ "Pressed",
+ "Indicates if the button is pressed in",
+ FALSE,
+ ST_PARAM_READABLE);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, props);
/**
@@ -631,7 +636,7 @@ st_button_set_label (StButton *button,
/* Fake a style change so that we reset the style properties on the label */
st_widget_style_changed (ST_WIDGET (button));
- g_object_notify (G_OBJECT (button), "label");
+ g_object_notify_by_pspec (G_OBJECT (button), props[PROP_LABEL]);
}
/**
@@ -670,7 +675,7 @@ st_button_set_button_mask (StButton *button,
priv = st_button_get_instance_private (button);
priv->button_mask = mask;
- g_object_notify (G_OBJECT (button), "button-mask");
+ g_object_notify_by_pspec (G_OBJECT (button), props[PROP_BUTTON_MASK]);
}
/**
@@ -708,7 +713,7 @@ st_button_set_toggle_mode (StButton *button,
priv = st_button_get_instance_private (button);
priv->is_toggle = toggle;
- g_object_notify (G_OBJECT (button), "toggle-mode");
+ g_object_notify_by_pspec (G_OBJECT (button), props[PROP_TOGGLE_MODE]);
}
/**
@@ -754,7 +759,7 @@ st_button_set_checked (StButton *button,
st_widget_remove_style_pseudo_class (ST_WIDGET (button), "checked");
}
- g_object_notify (G_OBJECT (button), "checked");
+ g_object_notify_by_pspec (G_OBJECT (button), props[PROP_CHECKED]);
}
/**
@@ -877,7 +882,7 @@ st_button_accessible_notify_label_cb (StButton *button,
GParamSpec *psec,
AtkObject *accessible)
{
- g_object_notify (G_OBJECT (accessible), "accessible-name");
+ g_object_notify_by_pspec (G_OBJECT (accessible), props[PROP_ACCESSIBLE_NAME]);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]