Refactor ph_merge_ordered() out of ph_merge().
diff --git a/include/jemalloc/internal/ph.h b/include/jemalloc/internal/ph.h
index aeca693..519f0dd 100644
--- a/include/jemalloc/internal/ph.h
+++ b/include/jemalloc/internal/ph.h
@@ -49,6 +49,7 @@
#ifdef JEMALLOC_H_INLINES
#ifndef JEMALLOC_ENABLE_INLINE
+ph_node_t *ph_merge_ordered(ph_node_t *heap1, ph_node_t *heap2);
ph_node_t *ph_merge(ph_node_t *heap1, ph_node_t *heap2);
ph_node_t *ph_merge_pairs(ph_node_t *subheaps);
void ph_merge_aux_list(ph_heap_t *l);
@@ -64,6 +65,23 @@
/* Helper routines ************************************************************/
JEMALLOC_INLINE ph_node_t *
+ph_merge_ordered(ph_node_t *heap1, ph_node_t *heap2)
+{
+
+ assert(heap1 != NULL);
+ assert(heap2 != NULL);
+ assert ((uintptr_t)heap1 <= (uintptr_t)heap2);
+
+ heap2->parent = heap1;
+ heap2->prev = NULL;
+ heap2->next = heap1->subheaps;
+ if (heap1->subheaps != NULL)
+ heap1->subheaps->prev = heap2;
+ heap1->subheaps = heap2;
+ return (heap1);
+}
+
+JEMALLOC_INLINE ph_node_t *
ph_merge(ph_node_t *heap1, ph_node_t *heap2)
{
@@ -72,23 +90,10 @@
if (heap2 == NULL)
return (heap1);
/* Optional: user-settable comparison function */
- if ((uintptr_t)heap1 < (uintptr_t)heap2) {
- heap2->parent = heap1;
- heap2->prev = NULL;
- heap2->next = heap1->subheaps;
- if (heap1->subheaps != NULL)
- heap1->subheaps->prev = heap2;
- heap1->subheaps = heap2;
- return (heap1);
- } else {
- heap1->parent = heap2;
- heap1->prev = NULL;
- heap1->next = heap2->subheaps;
- if (heap2->subheaps != NULL)
- heap2->subheaps->prev = heap1;
- heap2->subheaps = heap1;
- return (heap2);
- }
+ if ((uintptr_t)heap1 < (uintptr_t)heap2)
+ return (ph_merge_ordered(heap1, heap2));
+ else
+ return (ph_merge_ordered(heap2, heap1));
}
JEMALLOC_INLINE ph_node_t *
diff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt
index 2de1d5f..aeb43b1 100644
--- a/include/jemalloc/internal/private_symbols.txt
+++ b/include/jemalloc/internal/private_symbols.txt
@@ -383,6 +383,7 @@
ph_insert
ph_merge
ph_merge_aux_list
+ph_merge_ordered
ph_merge_pairs
ph_new
ph_remove_first