Simplify the logic in ph_insert
Also fixes what looks like an off by one error in the lazy aux list merge part of the code that previously never touched the last node in the aux list.
This commit is contained in:
parent
31e01a98f1
commit
543e2d61e6
@ -318,7 +318,9 @@ ph_insert(ph_t *ph, void *phn, size_t offset, ph_cmp_t cmp) {
|
|||||||
*/
|
*/
|
||||||
if (ph->root == NULL) {
|
if (ph->root == NULL) {
|
||||||
ph->root = phn;
|
ph->root = phn;
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* As a special case, check to see if we can replace the root.
|
* As a special case, check to see if we can replace the root.
|
||||||
* This is practically common in some important cases, and lets
|
* This is practically common in some important cases, and lets
|
||||||
@ -333,7 +335,7 @@ ph_insert(ph_t *ph, void *phn, size_t offset, ph_cmp_t cmp) {
|
|||||||
ph->auxcount = 0;
|
ph->auxcount = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ph->auxcount++;
|
|
||||||
phn_next_set(phn, phn_next_get(ph->root, offset), offset);
|
phn_next_set(phn, phn_next_get(ph->root, offset), offset);
|
||||||
if (phn_next_get(ph->root, offset) != NULL) {
|
if (phn_next_get(ph->root, offset) != NULL) {
|
||||||
phn_prev_set(phn_next_get(ph->root, offset), phn,
|
phn_prev_set(phn_next_get(ph->root, offset), phn,
|
||||||
@ -341,15 +343,14 @@ ph_insert(ph_t *ph, void *phn, size_t offset, ph_cmp_t cmp) {
|
|||||||
}
|
}
|
||||||
phn_prev_set(phn, ph->root, offset);
|
phn_prev_set(phn, ph->root, offset);
|
||||||
phn_next_set(ph->root, phn, offset);
|
phn_next_set(ph->root, phn, offset);
|
||||||
}
|
|
||||||
if (ph->auxcount > 1) {
|
ph->auxcount++;
|
||||||
unsigned nmerges = ffs_zu(ph->auxcount - 1);
|
unsigned nmerges = ffs_zu(ph->auxcount);
|
||||||
bool done = false;
|
bool done = false;
|
||||||
for (unsigned i = 0; i < nmerges && !done; i++) {
|
for (unsigned i = 0; i < nmerges && !done; i++) {
|
||||||
done = ph_try_aux_merge_pair(ph, offset, cmp);
|
done = ph_try_aux_merge_pair(ph, offset, cmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
JEMALLOC_ALWAYS_INLINE void *
|
JEMALLOC_ALWAYS_INLINE void *
|
||||||
ph_remove_first(ph_t *ph, size_t offset, ph_cmp_t cmp) {
|
ph_remove_first(ph_t *ph, size_t offset, ph_cmp_t cmp) {
|
||||||
|
Loading…
Reference in New Issue
Block a user