Bug 1415454 - Replace RedBlackTree::Init with a constructor. r?njn
Before 1412722, RedBlackTree actually needed a constructor to fill the
sentinel, but now, all it contains is a pointer to a root node, and an
empty tree just has a null root node. So we can use a constexpr
constructor for the class, which in most cases removes the need for
manual initialization/construction (being used as member of constructed
classes, or globals), except in the case of arena_bin_t, which is never
constructed.
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -1073,18 +1073,16 @@ struct ArenaTreeTrait
// - "private" arenas, used through the moz_arena_* API
// - all the other arenas: the default arena, and thread-local arenas,
// used by the standard API.
class ArenaCollection
{
public:
bool Init()
{
- mArenas.Init();
- mPrivateArenas.Init();
mDefaultArena =
mLock.Init() ? CreateArena(/* IsPrivate = */ false) : nullptr;
if (mDefaultArena) {
// arena_t constructor sets this to a lower value for thread local
// arenas; Reset to the default value for the main arena.
mDefaultArena->mMaxDirty = opt_dirty_max;
}
return bool(mDefaultArena);
@@ -2896,17 +2894,17 @@ arena_bin_t::Init(SizeClass aSizeClass)
// Size of the run header, excluding mRegionsMask.
static const size_t kRawHeaderSize = offsetof(arena_run_t, mRegionsMask);
MOZ_ASSERT(aSizeClass.Size() <= gMaxBinClass);
try_run_size = gPageSize;
mCurrentRun = nullptr;
- mNonFullRuns.Init();
+ new (&mNonFullRuns) RedBlackTree<arena_chunk_map_t, ArenaRunTreeTrait>();
mSizeClass = aSizeClass.Size();
mNumRuns = 0;
// mRunSize expansion loop.
while (true) {
try_nregs = ((try_run_size - kRawHeaderSize) / mSizeClass) +
1; // Counter-act try_nregs-- in loop.
@@ -3742,29 +3740,26 @@ arena_t::arena_t()
unsigned i;
MOZ_RELEASE_ASSERT(mLock.Init());
memset(&mLink, 0, sizeof(mLink));
memset(&mStats, 0, sizeof(arena_stats_t));
// Initialize chunks.
- mChunksDirty.Init();
#ifdef MALLOC_DOUBLE_PURGE
new (&mChunksMAdvised) DoublyLinkedList<arena_chunk_t>();
#endif
mSpare = nullptr;
mNumDirty = 0;
// Reduce the maximum amount of dirty pages we allow to be kept on
// thread local arenas. TODO: make this more flexible.
mMaxDirty = opt_dirty_max >> 3;
- mRunsAvail.Init();
-
// Initialize bins.
SizeClass sizeClass(1);
for (i = 0;; i++) {
arena_bin_t& bin = mBins[i];
bin.Init(sizeClass);
// SizeClass doesn't want sizes larger than gMaxSubPageClass for now.
@@ -4142,22 +4137,19 @@ static
}
}
}
gRecycledSize = 0;
// Initialize chunks data.
chunks_mtx.Init();
- gChunksBySize.Init();
- gChunksByAddress.Init();
// Initialize huge allocation data.
huge_mtx.Init();
- huge.Init();
huge_allocated = 0;
huge_mapped = 0;
// Initialize base allocation data structures.
base_mapped = 0;
base_committed = 0;
base_nodes = nullptr;
base_mtx.Init();
--- a/memory/build/rb.h
+++ b/memory/build/rb.h
@@ -117,17 +117,20 @@ public:
}
};
// Tree structure.
template<typename T, typename Trait>
class RedBlackTree
{
public:
- void Init() { mRoot = nullptr; }
+ constexpr RedBlackTree()
+ : mRoot(nullptr)
+ {
+ }
T* First(T* aStart = nullptr)
{
return First(reinterpret_cast<TreeNode*>(aStart));
}
T* Last(T* aStart = nullptr)
{