sd-netlink: append multipart messages in O(1)

Commit 52ceba53d3 made multipart replies append in receive
order, but each append walked the chain from the head.

Cache the tail on the chain head, so new fragments can be
linked directly. The visible next-pointer chain and order stay
unchanged.

Follow-up for: 52ceba53d3
This commit is contained in:
dongshengyuan
2026-08-05 23:18:09 +09:00
committed by Yu Watanabe
parent 0168430d91
commit 1a43aec562
2 changed files with 6 additions and 3 deletions
@@ -128,6 +128,7 @@ typedef struct sd_netlink_message {
bool sealed:1;
sd_netlink_message *next; /* next in a chain of multi-part messages */
sd_netlink_message *tail; /* last message in a multi-part chain */
} sd_netlink_message;
int message_new_empty(sd_netlink *nl, sd_netlink_message **ret);
+5 -3
View File
@@ -411,9 +411,11 @@ int socket_read_message(sd_netlink *nl) {
if (existing) {
/* This is the continuation of the previously read messages.
* Let's append this message at the end. */
while (existing->next)
existing = existing->next;
existing->next = TAKE_PTR(m);
if (existing->tail)
existing->tail->next = m;
else
existing->next = m;
existing->tail = TAKE_PTR(m);
} else {
/* This is the first message. Put it into the queue for partially
* received messages. */