From be0e037809de61cd9e9707310aafebcf44b6be10 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 19 Feb 2026 13:03:50 +0100 Subject: [PATCH] pulse-server: avoid doing allocations and string copies We can just concatenate the stream and client dict on the stack, reusing all the strings without having to do allocations or copies. Also filter out the object.id and object.serial from the client, we want to keep the ones from the streams. --- .../module-protocol-pulse/pulse-server.c | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 58dbb221a..24251942a 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -4072,18 +4072,38 @@ static int fill_node_info_proplist(struct message *m, const struct spa_dict *nod const struct pw_manager_object *client) { struct pw_client_info *client_info = client ? client->info : NULL; - spa_autoptr(pw_properties) props = NULL; + uint32_t n_items, n; + struct spa_dict dict, *client_props = NULL; + const struct spa_dict_item *it; + struct spa_dict_item *items, *it2; + n_items = node_props->n_items; if (client_info && client_info->props) { - props = pw_properties_new_dict(node_props); - if (props == NULL) - return -ENOMEM; - - pw_properties_add(props, client_info->props); - - node_props = &props->dict; + client_props = client_info->props; + n_items += client_props->n_items; } - message_put(m, TAG_PROPLIST, node_props, TAG_INVALID); + + dict.n_items = n = 0; + dict.items = items = alloca(n_items * sizeof(struct spa_dict_item)); + + spa_dict_for_each(it, node_props) + items[n++] = *it; + dict.n_items = n; + + if (client_props) { + spa_dict_for_each(it, client_props) { + if (spa_streq(it->key, PW_KEY_OBJECT_ID) || + spa_streq(it->key, PW_KEY_OBJECT_SERIAL)) + continue; + + if ((it2 = (struct spa_dict_item*)spa_dict_lookup_item(&dict, it->key))) + it2->value = it->value; + else + items[n++] = *it; + } + dict.n_items = n; + } + message_put(m, TAG_PROPLIST, &dict, TAG_INVALID); return 0; }