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] =
P_("Cursor Visible"), g_param_spec_boolean ("cursor-visible",
P_("Whether the mouse pointer is visible on the main stage"), P_("Cursor Visible"),
TRUE, P_("Whether the mouse pointer is visible on the main stage"),
CLUTTER_PARAM_READWRITE); TRUE,
g_object_class_install_property (gobject_class, CLUTTER_PARAM_READWRITE);
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] =
P_("Color"), clutter_param_spec_color ("color",
P_("The color of the stage"), P_("Color"),
&default_stage_color, P_("The color of the stage"),
CLUTTER_PARAM_READWRITE | &default_stage_color,
G_PARAM_DEPRECATED); CLUTTER_PARAM_READWRITE |
g_object_class_install_property (gobject_class, PROP_COLOR, pspec); G_PARAM_DEPRECATED);
/** /**
* 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] =
P_("Perspective"), g_param_spec_boxed ("perspective",
P_("Perspective projection parameters"), P_("Perspective"),
CLUTTER_TYPE_PERSPECTIVE, P_("Perspective projection parameters"),
CLUTTER_PARAM_READWRITE); CLUTTER_TYPE_PERSPECTIVE,
g_object_class_install_property (gobject_class, CLUTTER_PARAM_READWRITE);
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] =
P_("Title"), g_param_spec_string ("title",
P_("Stage Title"), P_("Title"),
NULL, P_("Stage Title"),
CLUTTER_PARAM_READWRITE); NULL,
g_object_class_install_property (gobject_class, PROP_TITLE, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* 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] =
P_("Use Fog"), g_param_spec_boolean ("use-fog",
P_("Whether to enable depth cueing"), P_("Use Fog"),
FALSE, P_("Whether to enable depth cueing"),
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED); FALSE,
g_object_class_install_property (gobject_class, PROP_USE_FOG, pspec); CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
/** /**
* 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] =
P_("Fog"), g_param_spec_boxed ("fog",
P_("Settings for the depth cueing"), P_("Fog"),
CLUTTER_TYPE_FOG, P_("Settings for the depth cueing"),
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED); CLUTTER_TYPE_FOG,
g_object_class_install_property (gobject_class, PROP_FOG, pspec); CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
/** /**
* 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] =
P_("Use Alpha"), g_param_spec_boolean ("use-alpha",
P_("Whether to honour the alpha component of the stage color"), P_("Use Alpha"),
FALSE, P_("Whether to honour the alpha component of the stage color"),
CLUTTER_PARAM_READWRITE); FALSE,
g_object_class_install_property (gobject_class, PROP_USE_ALPHA, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* 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] =
P_("Key Focus"), g_param_spec_object ("key-focus",
P_("The currently key focused actor"), P_("Key Focus"),
CLUTTER_TYPE_ACTOR, P_("The currently key focused actor"),
CLUTTER_PARAM_READWRITE); CLUTTER_TYPE_ACTOR,
g_object_class_install_property (gobject_class, PROP_KEY_FOCUS, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* 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] =
P_("No Clear Hint"), g_param_spec_boolean ("no-clear-hint",
P_("Whether the stage should clear its contents"), P_("No Clear Hint"),
FALSE, P_("Whether the stage should clear its contents"),
CLUTTER_PARAM_READWRITE); FALSE,
g_object_class_install_property (gobject_class, PROP_NO_CLEAR_HINT, pspec); CLUTTER_PARAM_READWRITE);
/** /**
* 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] =
P_("Accept Focus"), g_param_spec_boolean ("accept-focus",
P_("Whether the stage should accept focus on show"), P_("Accept Focus"),
TRUE, P_("Whether the stage should accept focus on show"),
CLUTTER_PARAM_READWRITE); TRUE,
g_object_class_install_property (gobject_class, PROP_ACCEPT_FOCUS, pspec); CLUTTER_PARAM_READWRITE);
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);
} }