Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: cc/base/contiguous_container_unittest.cc

Issue 2277433002: Defer allocation in cc::ContiguousContainerBase::Buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« cc/base/contiguous_container.cc ('K') | « cc/base/contiguous_container.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/contiguous_container_unittest.cc
diff --git a/cc/base/contiguous_container_unittest.cc b/cc/base/contiguous_container_unittest.cc
index 158b787d28dc4a584748e32b8861dc5e3decbc85..2a1d3d40bdc3b5c48ad70a9cf1d05892798d4f15 100644
--- a/cc/base/contiguous_container_unittest.cc
+++ b/cc/base/contiguous_container_unittest.cc
@@ -511,6 +511,33 @@ TEST(ContiguousContainerTest, CapacityInBytesAfterClear) {
EXPECT_EQ(empty_capacity, list.GetCapacityInBytes());
}
danakj 2016/08/23 18:16:00 Can you add a test that verifies we can use begin(
Dmitry Skiba 2016/08/24 17:58:46 Done.
+TEST(ContiguousContainerTest, MemoryUsageInBytes) {
+ constexpr size_t initial_size1 = 10 * kMaxPointSize;
+ ContiguousContainer<Point2D, kPointAlignment> list1(kMaxPointSize,
+ initial_size1);
+
+ constexpr size_t initial_size2 = 10000 * kMaxPointSize;
+ ContiguousContainer<Point2D, kPointAlignment> list2(kMaxPointSize,
+ initial_size2);
+
+ // Memory is allocated lazily, so even though lists were created with
+ // different initial_size values, they'll have the same memory size here.
+ EXPECT_EQ(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes());
danakj 2016/08/23 18:16:00 You could check LT initial_size here?
Dmitry Skiba 2016/08/24 17:58:46 I think that checking that would make us depend on
+
+ // Trigger memory allocation.
+ list1.AllocateAndConstruct<Point2D>();
+ list2.AllocateAndConstruct<Point2D>();
+
+ // Same object was created in both lists, but their memory sizes grew
+ // differently, based on initial_size values lists were created with.
+ EXPECT_NE(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes());
+
+ // Since memory size also includes other things, it should be greater
+ // than initial_size value.
+ EXPECT_GT(list1.MemoryUsageInBytes(), initial_size1);
+ EXPECT_GT(list2.MemoryUsageInBytes(), initial_size2);
+}
+
TEST(ContiguousContainerTest, Alignment) {
const size_t max_align = ALIGNOF(long double);
ContiguousContainer<Point2D, max_align> list(kMaxPointSize);
« cc/base/contiguous_container.cc ('K') | « cc/base/contiguous_container.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698