perf: use more efficient way to merge a linked list (#234)
diff --git a/rpmalloc/rpmalloc.c b/rpmalloc/rpmalloc.c
index 93a5931..d8329ec 100644
--- a/rpmalloc/rpmalloc.c
+++ b/rpmalloc/rpmalloc.c
@@ -1409,11 +1409,12 @@
keep = keep->next;
}
- while (keep) {
- span_t* next_span = keep->next;
- keep->next = cache->overflow;
+ if (keep) {
+ span_t* tail = keep;
+ while (tail->next)
+ tail = tail->next;
+ tail->next = cache->overflow;
cache->overflow = keep;
- keep = next_span;
}
atomic_store32_release(&cache->lock, 0);