From aa857bcdebc498a67c2129448f29109582a27d89 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 17 May 2021 19:51:09 +0200 Subject: [PATCH] LibJS: Always prefer freelist over lazy freelist if possible If we're able to allocate cells from a freelist, we should always prefer that over the lazy freelist, since this may further defer faulting in additional memory for the HeapBlock. Thanks to @gunnarbeutner for pointing this out. :^) --- Userland/Libraries/LibJS/Heap/HeapBlock.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Heap/HeapBlock.h b/Userland/Libraries/LibJS/Heap/HeapBlock.h index 3850b5e08b..e21ed79fdf 100644 --- a/Userland/Libraries/LibJS/Heap/HeapBlock.h +++ b/Userland/Libraries/LibJS/Heap/HeapBlock.h @@ -29,12 +29,13 @@ public: ALWAYS_INLINE Cell* allocate() { + if (m_freelist) { + VERIFY(is_valid_cell_pointer(m_freelist)); + return exchange(m_freelist, m_freelist->next); + } if (has_lazy_freelist()) return cell(m_next_lazy_freelist_index++); - if (!m_freelist) - return nullptr; - VERIFY(is_valid_cell_pointer(m_freelist)); - return exchange(m_freelist, m_freelist->next); + return nullptr; } void deallocate(Cell*);