mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
Issue #2148 - Shrink Vector from (usually) four pointers in size to three when no inline storage is used.
See Bug 1338374
This commit is contained in:
parent
0365f940fe
commit
481069044d
2 changed files with 168 additions and 82 deletions
|
|
@ -396,6 +396,49 @@ mozilla::detail::VectorTesting::testInsert()
|
|||
MOZ_RELEASE_ASSERT(S::destructCount == 1);
|
||||
}
|
||||
|
||||
// Declare but leave (permanently) incomplete.
|
||||
struct Incomplete;
|
||||
|
||||
// We could even *construct* a Vector<Incomplete, 0> if we wanted. But we can't
|
||||
// destruct it, so it's not worth the trouble.
|
||||
static_assert(sizeof(Vector<Incomplete, 0>) > 0,
|
||||
"Vector of an incomplete type will compile");
|
||||
|
||||
// Vector with no inline storage should occupy the absolute minimum space in
|
||||
// non-debug builds. (Debug adds a laundry list of other constraints, none
|
||||
// directly relevant to shipping builds, that aren't worth precisely modeling.)
|
||||
#ifndef DEBUG
|
||||
|
||||
template<typename T>
|
||||
struct NoInlineStorageLayout
|
||||
{
|
||||
T* mBegin;
|
||||
size_t mLength;
|
||||
struct CRAndStorage {
|
||||
size_t mCapacity;
|
||||
} mTail;
|
||||
};
|
||||
|
||||
// Only one of these should be necessary, but test a few of them for good
|
||||
// measure.
|
||||
static_assert(sizeof(Vector<int, 0>) == sizeof(NoInlineStorageLayout<int>),
|
||||
"Vector of int without inline storage shouldn't occupy dead "
|
||||
"space for that absence of storage");
|
||||
|
||||
static_assert(sizeof(Vector<bool, 0>) == sizeof(NoInlineStorageLayout<bool>),
|
||||
"Vector of bool without inline storage shouldn't occupy dead "
|
||||
"space for that absence of storage");
|
||||
|
||||
static_assert(sizeof(Vector<S, 0>) == sizeof(NoInlineStorageLayout<S>),
|
||||
"Vector of S without inline storage shouldn't occupy dead "
|
||||
"space for that absence of storage");
|
||||
|
||||
static_assert(sizeof(Vector<Incomplete, 0>) == sizeof(NoInlineStorageLayout<Incomplete>),
|
||||
"Vector of an incomplete class without inline storage shouldn't "
|
||||
"occupy dead space for that absence of storage");
|
||||
|
||||
#endif // DEBUG
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue