summaryrefslogtreecommitdiff
path: root/shared/nm-glib-aux/nm-macros-internal.h
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-20 14:43:13 +0200
committerThomas Haller <thaller@redhat.com>2020-07-23 15:29:19 +0200
commitabce54822249374b01010c73ac676a360581e22c (patch)
tree83e2f3538a78125150468f3db478b5358667c33e /shared/nm-glib-aux/nm-macros-internal.h
parente6acf64859fc1b4cc125608604cf38ae77c85367 (diff)
downloadNetworkManager-abce54822249374b01010c73ac676a360581e22c.tar.gz
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.
Diffstat (limited to 'shared/nm-glib-aux/nm-macros-internal.h')
-rw-r--r--shared/nm-glib-aux/nm-macros-internal.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h
index 9173d2792d..41f701f98e 100644
--- a/shared/nm-glib-aux/nm-macros-internal.h
+++ b/shared/nm-glib-aux/nm-macros-internal.h
@@ -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 \