mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibJS: Make BlockAllocator cache reuse blocks in random order
This commit is contained in:
parent
17f239e1c0
commit
23f4ff7247
Notes:
sideshowbarker
2024-07-18 02:56:13 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/23f4ff7247d
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Platform.h>
|
||||
#include <AK/Random.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Heap/BlockAllocator.h>
|
||||
#include <LibJS/Heap/HeapBlock.h>
|
||||
|
@ -38,7 +39,9 @@ BlockAllocator::~BlockAllocator()
|
|||
void* BlockAllocator::allocate_block([[maybe_unused]] char const* name)
|
||||
{
|
||||
if (!m_blocks.is_empty()) {
|
||||
auto* block = m_blocks.take_last();
|
||||
// To reduce predictability, take a random block from the cache.
|
||||
size_t random_index = get_random_uniform(m_blocks.size());
|
||||
auto* block = m_blocks.unstable_take(random_index);
|
||||
ASAN_UNPOISON_MEMORY_REGION(block, HeapBlock::block_size);
|
||||
#ifdef __serenity__
|
||||
if (set_mmap_name(block, HeapBlock::block_size, name) < 0) {
|
||||
|
|
Loading…
Reference in a new issue