Skip to content

Commit aa857bc

Browse files
committed
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. :^)
1 parent 6714cf3 commit aa857bc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Userland/Libraries/LibJS/Heap/HeapBlock.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class HeapBlock {
2929

3030
ALWAYS_INLINE Cell* allocate()
3131
{
32+
if (m_freelist) {
33+
VERIFY(is_valid_cell_pointer(m_freelist));
34+
return exchange(m_freelist, m_freelist->next);
35+
}
3236
if (has_lazy_freelist())
3337
return cell(m_next_lazy_freelist_index++);
34-
if (!m_freelist)
35-
return nullptr;
36-
VERIFY(is_valid_cell_pointer(m_freelist));
37-
return exchange(m_freelist, m_freelist->next);
38+
return nullptr;
3839
}
3940

4041
void deallocate(Cell*);

0 commit comments

Comments
 (0)