From abce54822249374b01010c73ac676a360581e22c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 20 Jul 2020 14:43:13 +0200 Subject: [PATCH] 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. --- shared/nm-glib-aux/nm-macros-internal.h | 34 ++++++++++++++++++------- 1 file 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 \