clutter: 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/mutter/merge_requests/703
This commit is contained in:
Niels De Graef 2019-07-25 08:46:28 +02:00 committed by Niels De Graef
parent 35007ebae0
commit ddbdb5fa77
3 changed files with 88 additions and 85 deletions

View File

@ -179,9 +179,12 @@ enum
PROP_USE_ALPHA, PROP_USE_ALPHA,
PROP_KEY_FOCUS, PROP_KEY_FOCUS,
PROP_NO_CLEAR_HINT, PROP_NO_CLEAR_HINT,
PROP_ACCEPT_FOCUS PROP_ACCEPT_FOCUS,
PROP_LAST
}; };
static GParamSpec *obj_props[PROP_LAST] = { NULL, };
enum enum
{ {
ACTIVATE, ACTIVATE,
@ -839,7 +842,7 @@ clutter_stage_emit_key_focus_event (ClutterStage *stage,
else else
g_signal_emit_by_name (priv->key_focused_actor, "key-focus-out"); g_signal_emit_by_name (priv->key_focused_actor, "key-focus-out");
g_object_notify (G_OBJECT (stage), "key-focus"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_KEY_FOCUS]);
} }
static void static void
@ -1877,7 +1880,6 @@ clutter_stage_class_init (ClutterStageClass *klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
GParamSpec *pspec;
gobject_class->constructed = clutter_stage_constructed; gobject_class->constructed = clutter_stage_constructed;
gobject_class->set_property = clutter_stage_set_property; gobject_class->set_property = clutter_stage_set_property;
@ -1908,14 +1910,13 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Whether the mouse pointer should be visible * Whether the mouse pointer should be visible
*/ */
pspec = g_param_spec_boolean ("cursor-visible", obj_props[PROP_CURSOR_VISIBLE] =
g_param_spec_boolean ("cursor-visible",
P_("Cursor Visible"), P_("Cursor Visible"),
P_("Whether the mouse pointer is visible on the main stage"), P_("Whether the mouse pointer is visible on the main stage"),
TRUE, TRUE,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_CURSOR_VISIBLE,
pspec);
/** /**
* ClutterStage:color: * ClutterStage:color:
* *
@ -1924,13 +1925,13 @@ clutter_stage_class_init (ClutterStageClass *klass)
* Deprecated: 1.10: Use the #ClutterActor:background-color property of * Deprecated: 1.10: Use the #ClutterActor:background-color property of
* #ClutterActor instead. * #ClutterActor instead.
*/ */
pspec = clutter_param_spec_color ("color", obj_props[PROP_COLOR] =
clutter_param_spec_color ("color",
P_("Color"), P_("Color"),
P_("The color of the stage"), P_("The color of the stage"),
&default_stage_color, &default_stage_color,
CLUTTER_PARAM_READWRITE | CLUTTER_PARAM_READWRITE |
G_PARAM_DEPRECATED); G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_COLOR, pspec);
/** /**
* ClutterStage:perspective: * ClutterStage:perspective:
@ -1940,14 +1941,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Since: 0.8 * Since: 0.8
*/ */
pspec = g_param_spec_boxed ("perspective", obj_props[PROP_PERSPECTIVE] =
g_param_spec_boxed ("perspective",
P_("Perspective"), P_("Perspective"),
P_("Perspective projection parameters"), P_("Perspective projection parameters"),
CLUTTER_TYPE_PERSPECTIVE, CLUTTER_TYPE_PERSPECTIVE,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_PERSPECTIVE,
pspec);
/** /**
* ClutterStage:title: * ClutterStage:title:
@ -1956,12 +1955,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Since: 0.4 * Since: 0.4
*/ */
pspec = g_param_spec_string ("title", obj_props[PROP_TITLE] =
g_param_spec_string ("title",
P_("Title"), P_("Title"),
P_("Stage Title"), P_("Stage Title"),
NULL, NULL,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_TITLE, pspec);
/** /**
* ClutterStage:use-fog: * ClutterStage:use-fog:
@ -1974,12 +1973,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Deprecated: 1.10: This property does not do anything. * Deprecated: 1.10: This property does not do anything.
*/ */
pspec = g_param_spec_boolean ("use-fog", obj_props[PROP_USE_FOG] =
g_param_spec_boolean ("use-fog",
P_("Use Fog"), P_("Use Fog"),
P_("Whether to enable depth cueing"), P_("Whether to enable depth cueing"),
FALSE, FALSE,
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED); CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_USE_FOG, pspec);
/** /**
* ClutterStage:fog: * ClutterStage:fog:
@ -1991,12 +1990,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Deprecated: 1.10: This property does not do anything. * Deprecated: 1.10: This property does not do anything.
*/ */
pspec = g_param_spec_boxed ("fog", obj_props[PROP_FOG] =
g_param_spec_boxed ("fog",
P_("Fog"), P_("Fog"),
P_("Settings for the depth cueing"), P_("Settings for the depth cueing"),
CLUTTER_TYPE_FOG, CLUTTER_TYPE_FOG,
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED); CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_FOG, pspec);
/** /**
* ClutterStage:use-alpha: * ClutterStage:use-alpha:
@ -2008,12 +2007,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_boolean ("use-alpha", obj_props[PROP_USE_ALPHA] =
g_param_spec_boolean ("use-alpha",
P_("Use Alpha"), P_("Use Alpha"),
P_("Whether to honour the alpha component of the stage color"), P_("Whether to honour the alpha component of the stage color"),
FALSE, FALSE,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_USE_ALPHA, pspec);
/** /**
* ClutterStage:key-focus: * ClutterStage:key-focus:
@ -2025,12 +2024,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Since: 1.2 * Since: 1.2
*/ */
pspec = g_param_spec_object ("key-focus", obj_props[PROP_KEY_FOCUS] =
g_param_spec_object ("key-focus",
P_("Key Focus"), P_("Key Focus"),
P_("The currently key focused actor"), P_("The currently key focused actor"),
CLUTTER_TYPE_ACTOR, CLUTTER_TYPE_ACTOR,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_KEY_FOCUS, pspec);
/** /**
* ClutterStage:no-clear-hint: * ClutterStage:no-clear-hint:
@ -2042,12 +2041,12 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Since: 1.4 * Since: 1.4
*/ */
pspec = g_param_spec_boolean ("no-clear-hint", obj_props[PROP_NO_CLEAR_HINT] =
g_param_spec_boolean ("no-clear-hint",
P_("No Clear Hint"), P_("No Clear Hint"),
P_("Whether the stage should clear its contents"), P_("Whether the stage should clear its contents"),
FALSE, FALSE,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_NO_CLEAR_HINT, pspec);
/** /**
* ClutterStage:accept-focus: * ClutterStage:accept-focus:
@ -2056,12 +2055,14 @@ clutter_stage_class_init (ClutterStageClass *klass)
* *
* Since: 1.6 * Since: 1.6
*/ */
pspec = g_param_spec_boolean ("accept-focus", obj_props[PROP_ACCEPT_FOCUS] =
g_param_spec_boolean ("accept-focus",
P_("Accept Focus"), P_("Accept Focus"),
P_("Whether the stage should accept focus on show"), P_("Whether the stage should accept focus on show"),
TRUE, TRUE,
CLUTTER_PARAM_READWRITE); CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_ACCEPT_FOCUS, pspec);
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
/** /**
* ClutterStage::activate: * ClutterStage::activate:
@ -2359,7 +2360,7 @@ clutter_stage_set_color (ClutterStage *stage,
{ {
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), color); clutter_actor_set_background_color (CLUTTER_ACTOR (stage), color);
g_object_notify (G_OBJECT (stage), "color"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_COLOR]);
} }
/** /**
@ -2649,7 +2650,8 @@ clutter_stage_show_cursor (ClutterStage *stage)
iface->set_cursor_visible (impl, TRUE); iface->set_cursor_visible (impl, TRUE);
g_object_notify (G_OBJECT (stage), "cursor-visible"); g_object_notify_by_pspec (G_OBJECT (stage),
obj_props[PROP_CURSOR_VISIBLE]);
} }
} }
} }
@ -2682,7 +2684,8 @@ clutter_stage_hide_cursor (ClutterStage *stage)
iface->set_cursor_visible (impl, FALSE); iface->set_cursor_visible (impl, FALSE);
g_object_notify (G_OBJECT (stage), "cursor-visible"); g_object_notify_by_pspec (G_OBJECT (stage),
obj_props[PROP_CURSOR_VISIBLE]);
} }
} }
} }
@ -2894,7 +2897,7 @@ clutter_stage_set_title (ClutterStage *stage,
if (CLUTTER_STAGE_WINDOW_GET_IFACE(impl)->set_title != NULL) if (CLUTTER_STAGE_WINDOW_GET_IFACE(impl)->set_title != NULL)
CLUTTER_STAGE_WINDOW_GET_IFACE (impl)->set_title (impl, priv->title); CLUTTER_STAGE_WINDOW_GET_IFACE (impl)->set_title (impl, priv->title);
g_object_notify (G_OBJECT (stage), "title"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_TITLE]);
} }
/** /**
@ -2994,7 +2997,7 @@ clutter_stage_set_key_focus (ClutterStage *stage,
else else
g_signal_emit_by_name (stage, "key-focus-in"); g_signal_emit_by_name (stage, "key-focus-in");
g_object_notify (G_OBJECT (stage), "key-focus"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_KEY_FOCUS]);
} }
/** /**
@ -3672,7 +3675,7 @@ clutter_stage_set_use_alpha (ClutterStage *stage,
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
g_object_notify (G_OBJECT (stage), "use-alpha"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_USE_ALPHA]);
} }
} }
@ -3886,7 +3889,7 @@ clutter_stage_set_no_clear_hint (ClutterStage *stage,
priv->stage_hints = new_hints; priv->stage_hints = new_hints;
g_object_notify (G_OBJECT (stage), "no-clear-hint"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_NO_CLEAR_HINT]);
} }
/** /**
@ -4128,7 +4131,7 @@ clutter_stage_set_accept_focus (ClutterStage *stage,
if (priv->accept_focus != accept_focus) if (priv->accept_focus != accept_focus)
{ {
_clutter_stage_window_set_accept_focus (priv->impl, accept_focus); _clutter_stage_window_set_accept_focus (priv->impl, accept_focus);
g_object_notify (G_OBJECT (stage), "accept-focus"); g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_ACCEPT_FOCUS]);
} }
} }

View File

@ -228,8 +228,8 @@ clutter_text_buffer_real_inserted_text (ClutterTextBuffer *buffer,
const gchar *chars, const gchar *chars,
guint n_chars) guint n_chars)
{ {
g_object_notify (G_OBJECT (buffer), "text"); g_object_notify_by_pspec (G_OBJECT (buffer), obj_props[PROP_TEXT]);
g_object_notify (G_OBJECT (buffer), "length"); g_object_notify_by_pspec (G_OBJECT (buffer), obj_props[PROP_LENGTH]);
} }
static void static void
@ -237,8 +237,8 @@ clutter_text_buffer_real_deleted_text (ClutterTextBuffer *buffer,
guint position, guint position,
guint n_chars) guint n_chars)
{ {
g_object_notify (G_OBJECT (buffer), "text"); g_object_notify_by_pspec (G_OBJECT (buffer), obj_props[PROP_TEXT]);
g_object_notify (G_OBJECT (buffer), "length"); g_object_notify_by_pspec (G_OBJECT (buffer), obj_props[PROP_LENGTH]);
} }
/* -------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------
@ -598,7 +598,7 @@ clutter_text_buffer_set_max_length (ClutterTextBuffer *buffer,
clutter_text_buffer_delete_text (buffer, max_length, -1); clutter_text_buffer_delete_text (buffer, max_length, -1);
buffer->priv->max_length = max_length; buffer->priv->max_length = max_length;
g_object_notify (G_OBJECT (buffer), "max-length"); g_object_notify_by_pspec (G_OBJECT (buffer), obj_props[PROP_MAX_LENGTH]);
} }
/** /**

View File

@ -4821,7 +4821,7 @@ buffer_notify_max_length (ClutterTextBuffer *buffer,
GParamSpec *spec, GParamSpec *spec,
ClutterText *self) ClutterText *self)
{ {
g_object_notify (G_OBJECT (self), "max-length"); g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MAX_LENGTH]);
} }
static void static void
@ -4920,9 +4920,9 @@ clutter_text_set_buffer (ClutterText *self,
obj = G_OBJECT (self); obj = G_OBJECT (self);
g_object_freeze_notify (obj); g_object_freeze_notify (obj);
g_object_notify (obj, "buffer"); g_object_notify_by_pspec (obj, obj_props[PROP_BUFFER]);
g_object_notify (obj, "text"); g_object_notify_by_pspec (obj, obj_props[PROP_TEXT]);
g_object_notify (obj, "max-length"); g_object_notify_by_pspec (obj, obj_props[PROP_MAX_LENGTH]);
g_object_thaw_notify (obj); g_object_thaw_notify (obj);
} }