Insert 'new_node' after 'old_node' if 'after' is 1. * Insert 'new_node' before 'old_node' if 'after' is 0. * Note: 'new_node' is *always* uncompressed, so if we assign it to * head or tail, we do not need to uncompress it. */
| 357 | * Note: 'new_node' is *always* uncompressed, so if we assign it to |
| 358 | * head or tail, we do not need to uncompress it. */ |
| 359 | REDIS_STATIC void __quicklistInsertNode(quicklist *quicklist, |
| 360 | quicklistNode *old_node, |
| 361 | quicklistNode *new_node, int after) { |
| 362 | if (after) { |
| 363 | new_node->prev = old_node; |
| 364 | if (old_node) { |
| 365 | new_node->next = old_node->next; |
| 366 | if (old_node->next) |
| 367 | old_node->next->prev = new_node; |
| 368 | old_node->next = new_node; |
| 369 | } |
| 370 | if (quicklist->tail == old_node) |
| 371 | quicklist->tail = new_node; |
| 372 | } else { |
| 373 | new_node->next = old_node; |
| 374 | if (old_node) { |
| 375 | new_node->prev = old_node->prev; |
| 376 | if (old_node->prev) |
| 377 | old_node->prev->next = new_node; |
| 378 | old_node->prev = new_node; |
| 379 | } |
| 380 | if (quicklist->head == old_node) |
| 381 | quicklist->head = new_node; |
| 382 | } |
| 383 | /* If this insert creates the only element so far, initialize head/tail. */ |
| 384 | if (quicklist->len == 0) { |
| 385 | quicklist->head = quicklist->tail = new_node; |
| 386 | } |
| 387 | |
| 388 | /* Update len first, so in __quicklistCompress we know exactly len */ |
| 389 | quicklist->len++; |
| 390 | |
| 391 | if (old_node) |
| 392 | quicklistCompress(quicklist, old_node); |
| 393 | } |
| 394 | |
| 395 | /* Wrappers for node inserting around existing node. */ |
| 396 | REDIS_STATIC void _quicklistInsertNodeBefore(quicklist *quicklist, |
no outgoing calls
no test coverage detected