driver/name-owner-changed: create the notification message lazily
Only if there are subscribers/monitors will we actually create the
notification message.
This should not make a huge difference, but in the common case,
nobody cares about the change of a given name, so avoid doing the
work.
@@ -565,6 +565,17 @@ static int driver_notify_name_owner_changed(Bus *bus, MatchRegistry *matches, co
.n_args = 3,
.n_argpaths = 3,
};
+ int r;
+
+ r = bus_get_monitor_destinations(bus, &destinations, NULL, &filter);
+ if (r)
+ return error_trace(r);
+
+ r = bus_get_broadcast_destinations(bus, &destinations, matches, NULL, &filter);
+ if (r)
+ return error_trace(r);
+
+ if (!c_list_is_empty(&destinations)) {
static const CDVarType type[] = {
C_DVAR_T_INIT(
DRIVER_T_MESSAGE(
@@ -580,7 +591,6 @@ static int driver_notify_name_owner_changed(Bus *bus, MatchRegistry *matches, co
_c_cleanup_(message_unrefp) Message *message = NULL;
_c_cleanup_(c_freep) void *data = NULL;
size_t n_data;
- int r;
c_dvar_begin_write(&var, type, 1);
c_dvar_write(&var, "(");
@@ -596,14 +606,6 @@ static int driver_notify_name_owner_changed(Bus *bus, MatchRegistry *matches, co
return error_fold(r);
data = NULL;
- r = bus_get_monitor_destinations(bus, &destinations, NULL, &filter);
- if (r)
- return error_trace(r);
-
- r = bus_get_broadcast_destinations(bus, &destinations, matches, NULL, &filter);
- if (r)
- return error_trace(r);
-
c_list_for_each_entry(receiver, &destinations, destinations_link) {
r = connection_queue(&receiver->connection, NULL, message);
if (r) {
@@ -613,6 +615,7 @@ static int driver_notify_name_owner_changed(Bus *bus, MatchRegistry *matches, co
return error_fold(r);
}
}
+ }
return 0;
}
