ladybird/Userland/Libraries/LibJS/Runtime/WeakContainer.h
Andreas Kling 83bd675477 LibJS: Make WeakContainer pruning do less work
Instead of iterating *all* swept cells when pruning weak containers,
only iterate the cells actually *in* the container.

Also, instead of compiling a list of all swept cells, we can simply
check the Cell::state() flag to know if something should be pruned.
2021-10-05 18:52:00 +02:00

33 lines
552 B
C++

/*
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/IntrusiveList.h>
namespace JS {
class WeakContainer {
public:
explicit WeakContainer(Heap&);
virtual ~WeakContainer();
virtual void remove_dead_cells(Badge<Heap>) = 0;
protected:
void deregister();
private:
bool m_registered { true };
Heap& m_heap;
IntrusiveListNode<WeakContainer> m_list_node;
public:
using List = IntrusiveList<&WeakContainer::m_list_node>;
};
}