Bug 1903483 - Simplify nsFrameList::EmptyList() allocation. r=layout-reviewers,emilio

Bug 729519 [1] made the empty frame list be allocated in the
`.rodata` (read-only) section. However, the setup can be simplified.

To verify that `sEmptyList` is still allocated in the `.rodata` section, I used
the following steps on my local Linux build:

1. Move `nsFrameList.cpp` in moz.build from UNIFIED_SOURCES to SOURCES.
2. Run `./mach build`.
3. Run `objdump -x $(OBJDIR)/layout/generic/nsFrameList.o | grep sEmptyList`.
4. Verify that the output `sEmptyList` has `.rodata`. The objdump output looks
   like this:

```
0000000000000038 g     O .rodata	0000000000000010 .hidden _ZN11nsFrameList10sEmptyListE
```

[1] Specifically, this commit:
https://hg.mozilla.org/mozilla-central/rev/c320c5821f98

Differential Revision: https://phabricator.services.mozilla.com/D214226
This commit is contained in:
Ting-Yu Lin 2024-06-19 21:48:29 +00:00
parent ae232d2b95
commit f478ee1b96
2 changed files with 5 additions and 20 deletions

View File

@ -18,11 +18,7 @@
using namespace mozilla;
namespace mozilla {
namespace detail {
const AlignedFrameListBytes gEmptyFrameListBytes = {0};
} // namespace detail
} // namespace mozilla
const nsFrameList nsFrameList::sEmptyList;
void* nsFrameList::operator new(size_t sz, mozilla::PresShell* aPresShell) {
return aPresShell->AllocateByObjectID(eArenaObjectID_nsFrameList, sz);

View File

@ -81,7 +81,7 @@ class nsFrameList {
using reverse_iterator = Iterator<BackwardFrameTraversal>;
using const_reverse_iterator = Iterator<BackwardFrameTraversal>;
nsFrameList() : mFirstChild(nullptr), mLastChild(nullptr) {}
constexpr nsFrameList() : mFirstChild(nullptr), mLastChild(nullptr) {}
nsFrameList(nsIFrame* aFirstFrame, nsIFrame* aLastFrame)
: mFirstChild(aFirstFrame), mLastChild(aLastFrame) {
@ -336,7 +336,7 @@ class nsFrameList {
void List(FILE* out) const;
#endif
static inline const nsFrameList& EmptyList();
static inline const nsFrameList& EmptyList() { return sEmptyList; };
/**
* A class representing a slice of a frame list.
@ -425,6 +425,8 @@ class nsFrameList {
private:
void operator delete(void*) = delete;
static const nsFrameList sEmptyList;
#ifdef DEBUG_FRAME_LIST
void VerifyList() const;
#else
@ -478,19 +480,6 @@ class MOZ_RAII AutoFrameListPtr final {
nsFrameList* mFrameList;
};
namespace detail {
union AlignedFrameListBytes {
void* ptr;
char bytes[sizeof(nsFrameList)];
};
extern const AlignedFrameListBytes gEmptyFrameListBytes;
} // namespace detail
} // namespace mozilla
/* static */ inline const nsFrameList& nsFrameList::EmptyList() {
return *reinterpret_cast<const nsFrameList*>(
&mozilla::detail::gEmptyFrameListBytes);
}
#endif /* nsFrameList_h___ */