Optimize meld in qr module
The goal of `qr_meld()` is to change the following four fields `(a->prev, a->prev->next, b->prev, b->prev->next)` from the values `(a->prev, a, b->prev, b)` to `(b->prev, b, a->prev, a)`. This commit changes ``` a->prev->next = b; b->prev->next = a; temp = a->prev; a->prev = b->prev; b->prev = temp; ``` to ``` temp = a->prev; a->prev = b->prev; b->prev = temp; a->prev->next = a; b->prev->next = b; ``` The benefit is that we can use `b->prev->next` for `temp`, and so there's no need to pass in `a_type`. The restriction is that `b` cannot be a `qr_next()` macro, so users of `qr_meld()` must pay attention. (Before this change, neither `a` nor `b` could be a `qr_next()` macro.)
This commit is contained in:
@@ -212,22 +212,22 @@ TEST_BEGIN(test_qr_meld_split) {
|
||||
qr_after_insert(&entries[i - 1], &entries[i], link);
|
||||
}
|
||||
|
||||
qr_split(&entries[0], &entries[SPLIT_INDEX], ring_t, link);
|
||||
qr_split(&entries[0], &entries[SPLIT_INDEX], link);
|
||||
test_split_entries(entries);
|
||||
|
||||
qr_meld(&entries[0], &entries[SPLIT_INDEX], ring_t, link);
|
||||
qr_meld(&entries[0], &entries[SPLIT_INDEX], link);
|
||||
test_entries_ring(entries);
|
||||
|
||||
qr_meld(&entries[0], &entries[SPLIT_INDEX], ring_t, link);
|
||||
qr_meld(&entries[0], &entries[SPLIT_INDEX], link);
|
||||
test_split_entries(entries);
|
||||
|
||||
qr_split(&entries[0], &entries[SPLIT_INDEX], ring_t, link);
|
||||
qr_split(&entries[0], &entries[SPLIT_INDEX], link);
|
||||
test_entries_ring(entries);
|
||||
|
||||
qr_split(&entries[0], &entries[0], ring_t, link);
|
||||
qr_split(&entries[0], &entries[0], link);
|
||||
test_entries_ring(entries);
|
||||
|
||||
qr_meld(&entries[0], &entries[0], ring_t, link);
|
||||
qr_meld(&entries[0], &entries[0], link);
|
||||
test_entries_ring(entries);
|
||||
}
|
||||
TEST_END
|
||||
|
Reference in New Issue
Block a user