shared: don't freeze in nm_gobject_notify_together() unless necessary

nm_gobject_notify_together() is supposed to emit one or more property changed
notifications, but with freezing (and thawing) the notifications.

Also, we want to allow the user to pass PROP_0, for skipping emitions.
The point is code like

  nm_gobject_notify_together (obj,
                              PROP_FOO,
                              bar_changed ? PROP_BAR : PROP_0);

Optimize the code to only freeze/thaw the notifications, if we are
actually notifying more than one properties.
This commit is contained in:
Thomas Haller 2020-07-20 14:43:13 +02:00
parent e6acf64859
commit abce548222
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -700,24 +700,40 @@ static GParamSpec *obj_properties##suffix[_PROPERTY_ENUMS_LAST##suffix] = { NULL
static inline void \
_nm_gobject_notify_together_impl##suffix (obj_type *obj, guint n, const _PropertyEnums##suffix *props) \
{ \
const gboolean freeze_thaw = (n > 1); \
GObject *const gobj = (GObject *) obj; \
GParamSpec *pspec_first = NULL; \
gboolean frozen = FALSE; \
\
nm_assert (G_IS_OBJECT (obj)); \
nm_assert (n > 0); \
\
if (freeze_thaw) \
g_object_freeze_notify ((GObject *) obj); \
while (n-- > 0) { \
const _PropertyEnums##suffix prop = *props++; \
GParamSpec *pspec; \
\
if (prop != PROP_0##suffix) { \
nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties##suffix)); \
nm_assert (obj_properties##suffix[prop]); \
g_object_notify_by_pspec ((GObject *) obj, obj_properties##suffix[prop]); \
if (prop == PROP_0##suffix) \
continue; \
\
nm_assert ((gsize) prop < G_N_ELEMENTS (obj_properties##suffix)); \
pspec = obj_properties##suffix[prop]; \
nm_assert (pspec); \
\
if (!frozen) { \
if (!pspec_first) { \
pspec_first = pspec; \
continue; \
} \
frozen = TRUE; \
g_object_freeze_notify (gobj); \
g_object_notify_by_pspec (gobj, pspec_first); \
} \
g_object_notify_by_pspec (gobj, pspec); \
} \
if (freeze_thaw) \
g_object_thaw_notify ((GObject *) obj); \
\
if (frozen) \
g_object_thaw_notify (gobj); \
else if (pspec_first) \
g_object_notify_by_pspec (gobj, pspec_first); \
} \
\
_nm_unused static inline void \