summaryrefslogtreecommitdiff
path: root/mfbt/tests
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2023-03-09 15:10:02 +0800
committerMoonchild <moonchild@palemoon.org>2023-03-15 13:02:23 +0100
commit68f456b5fd092c2a5e0e22ad76dd4b3a6f1d3632 (patch)
treee9baeb61b2ef8e24b5e745db19af4a8474c2329b /mfbt/tests
parent9475b959d79bb5da362a1097de8a5ca98c344110 (diff)
downloaduxp-68f456b5fd092c2a5e0e22ad76dd4b3a6f1d3632.tar.gz
Issue #2148 - Shrink Vector from (usually) four pointers in size to three
when no inline storage is used. See Bug 1338374
Diffstat (limited to 'mfbt/tests')
-rw-r--r--mfbt/tests/TestVector.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/mfbt/tests/TestVector.cpp b/mfbt/tests/TestVector.cpp
index 24baf8eae7..9aed9e617c 100644
--- a/mfbt/tests/TestVector.cpp
+++ b/mfbt/tests/TestVector.cpp
@@ -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()
{