diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /layout/base/nsPresArena.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/base/nsPresArena.h')
-rw-r--r-- | layout/base/nsPresArena.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/layout/base/nsPresArena.h b/layout/base/nsPresArena.h new file mode 100644 index 0000000000..884f2b44c5 --- /dev/null +++ b/layout/base/nsPresArena.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* arena allocation for the frame tree and closely-related objects */ + +#ifndef nsPresArena_h___ +#define nsPresArena_h___ + +#include "mozilla/ArenaAllocator.h" +#include "mozilla/ArenaObjectID.h" +#include "mozilla/Assertions.h" +#include "mozilla/MemoryChecking.h" // Note: Do not remove this, needed for MOZ_HAVE_MEM_CHECKS below +#include "mozilla/MemoryReporting.h" +#include <stdint.h> +#include "nscore.h" +#include "nsHashKeys.h" +#include "nsTArray.h" +#include "nsTHashtable.h" + +class nsWindowSizes; + +template <size_t ArenaSize, typename ObjectId, size_t ObjectIdCount> +class nsPresArena { + public: + nsPresArena() = default; + ~nsPresArena(); + + /** + * Pool allocation with recycler lists indexed by object-type ID (see above). + * Every aID must always be used with the same object size, aSize. + */ + void* Allocate(ObjectId aCode, size_t aSize); + void Free(ObjectId aCode, void* aPtr); + + enum class ArenaKind { PresShell, DisplayList }; + /** + * Increment nsWindowSizes with sizes of interesting objects allocated in this + * arena, and put the general unclassified size in the relevant field + * depending on the arena size. + */ + void AddSizeOfExcludingThis(nsWindowSizes&, ArenaKind) const; + + void Check() { mPool.Check(); } + + private: + class FreeList { + public: + nsTArray<void*> mEntries; + size_t mEntrySize; + size_t mEntriesEverAllocated; + + FreeList() : mEntrySize(0), mEntriesEverAllocated(0) {} + + size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { + return mEntries.ShallowSizeOfExcludingThis(aMallocSizeOf); + } + }; + + FreeList mFreeLists[ObjectIdCount]; + mozilla::ArenaAllocator<ArenaSize, 8> mPool; +}; + +#endif |