MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / listInsertNode

Function listInsertNode

src/adlist.c:135–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135list *listInsertNode(list *list, listNode *old_node, void *value, int after) {
136 listNode *node;
137
138 if ((node = zmalloc(sizeof(*node), MALLOC_SHARED)) == NULL)
139 return NULL;
140 node->value = value;
141 if (after) {
142 node->prev = old_node;
143 node->next = old_node->next;
144 if (list->tail == old_node) {
145 list->tail = node;
146 }
147 } else {
148 node->next = old_node;
149 node->prev = old_node->prev;
150 if (list->head == old_node) {
151 list->head = node;
152 }
153 }
154 if (node->prev != NULL) {
155 node->prev->next = node;
156 }
157 if (node->next != NULL) {
158 node->next->prev = node;
159 }
160 list->len++;
161 return list;
162}
163
164/* Remove the specified node from the specified list.
165 * It's up to the caller to free the private value of the node.

Callers

nothing calls this directly

Calls 1

zmallocFunction · 0.85

Tested by

no test coverage detected