summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Séchet <deadalnix@gmail.com>2023-03-03 12:35:45 +0000
committerQi Wang <interwq@gmail.com>2023-03-31 14:35:31 -0700
commit5266152d7922fc76fdaaa39ded9381a4fa7b4b9d (patch)
tree7cda4ca7d51f66cc54a863229392c1d569279123
parentbe6da4f663a062353dd9a25baaae0ebcd68b7477 (diff)
downloadjemalloc-5266152d7922fc76fdaaa39ded9381a4fa7b4b9d.tar.gz
Simplify the logic in ph_remove
-rw-r--r--include/jemalloc/internal/ph.h64
1 files changed, 20 insertions, 44 deletions
diff --git a/include/jemalloc/internal/ph.h b/include/jemalloc/internal/ph.h
index 0cc41eab..c3cf8743 100644
--- a/include/jemalloc/internal/ph.h
+++ b/include/jemalloc/internal/ph.h
@@ -369,9 +369,6 @@ ph_remove_first(ph_t *ph, size_t offset, ph_cmp_t cmp) {
JEMALLOC_ALWAYS_INLINE void
ph_remove(ph_t *ph, void *phn, size_t offset, ph_cmp_t cmp) {
- void *replace;
- void *parent;
-
if (ph->root == phn) {
/*
* We can delete from aux list without merging it, but we need
@@ -389,50 +386,29 @@ ph_remove(ph_t *ph, void *phn, size_t offset, ph_cmp_t cmp) {
}
}
- /* Get parent (if phn is leftmost child) before mutating. */
- if ((parent = phn_prev_get(phn, offset)) != NULL) {
- if (phn_lchild_get(parent, offset) != phn) {
- parent = NULL;
- }
- }
- /* Find a possible replacement node, and link to parent. */
- replace = ph_merge_children(phn, offset, cmp);
- /* Set next/prev for sibling linked list. */
+ void* prev = phn_prev_get(phn, offset);
+ void* next = phn_next_get(phn, offset);
+
+ /* If we have children, then we integrate them back in the heap. */
+ void* replace = ph_merge_children(phn, offset, cmp);
if (replace != NULL) {
- if (parent != NULL) {
- phn_prev_set(replace, parent, offset);
- phn_lchild_set(parent, replace, offset);
- } else {
- phn_prev_set(replace, phn_prev_get(phn, offset),
- offset);
- if (phn_prev_get(phn, offset) != NULL) {
- phn_next_set(phn_prev_get(phn, offset), replace,
- offset);
- }
- }
- phn_next_set(replace, phn_next_get(phn, offset), offset);
- if (phn_next_get(phn, offset) != NULL) {
- phn_prev_set(phn_next_get(phn, offset), replace,
- offset);
+ phn_next_set(replace, next, offset);
+ if (next != NULL) {
+ phn_prev_set(next, replace, offset);
}
+
+ next = replace;
+ }
+
+ if (next != NULL) {
+ phn_prev_set(next, prev, offset);
+ }
+
+ assert(prev != NULL);
+ if (phn_lchild_get(prev, offset) == phn) {
+ phn_lchild_set(prev, next, offset);
} else {
- if (parent != NULL) {
- void *next = phn_next_get(phn, offset);
- phn_lchild_set(parent, next, offset);
- if (next != NULL) {
- phn_prev_set(next, parent, offset);
- }
- } else {
- assert(phn_prev_get(phn, offset) != NULL);
- phn_next_set(
- phn_prev_get(phn, offset),
- phn_next_get(phn, offset), offset);
- }
- if (phn_next_get(phn, offset) != NULL) {
- phn_prev_set(
- phn_next_get(phn, offset),
- phn_prev_get(phn, offset), offset);
- }
+ phn_next_set(prev, next, offset);
}
}