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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "cc/base/contiguous_container.h" 7 #include "cc/base/contiguous_container.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 TEST(ContiguousContainerTest, CapacityInBytesAfterClear) { 503 TEST(ContiguousContainerTest, CapacityInBytesAfterClear) {
504 // Clearing should restore the capacity of the container to the same as a 504 // Clearing should restore the capacity of the container to the same as a
505 // newly allocated one (without reserved capacity requested). 505 // newly allocated one (without reserved capacity requested).
506 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize); 506 ContiguousContainer<Point2D, kPointAlignment> list(kMaxPointSize);
507 size_t empty_capacity = list.GetCapacityInBytes(); 507 size_t empty_capacity = list.GetCapacityInBytes();
508 list.AllocateAndConstruct<Point2D>(); 508 list.AllocateAndConstruct<Point2D>();
509 list.AllocateAndConstruct<Point2D>(); 509 list.AllocateAndConstruct<Point2D>();
510 list.Clear(); 510 list.Clear();
511 EXPECT_EQ(empty_capacity, list.GetCapacityInBytes()); 511 EXPECT_EQ(empty_capacity, list.GetCapacityInBytes());
512 } 512 }
513 513
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.
514 TEST(ContiguousContainerTest, MemoryUsageInBytes) {
515 constexpr size_t initial_size1 = 10 * kMaxPointSize;
516 ContiguousContainer<Point2D, kPointAlignment> list1(kMaxPointSize,
517 initial_size1);
518
519 constexpr size_t initial_size2 = 10000 * kMaxPointSize;
520 ContiguousContainer<Point2D, kPointAlignment> list2(kMaxPointSize,
521 initial_size2);
522
523 // Memory is allocated lazily, so even though lists were created with
524 // different initial_size values, they'll have the same memory size here.
525 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
526
527 // Trigger memory allocation.
528 list1.AllocateAndConstruct<Point2D>();
529 list2.AllocateAndConstruct<Point2D>();
530
531 // Same object was created in both lists, but their memory sizes grew
532 // differently, based on initial_size values lists were created with.
533 EXPECT_NE(list1.MemoryUsageInBytes(), list2.MemoryUsageInBytes());
534
535 // Since memory size also includes other things, it should be greater
536 // than initial_size value.
537 EXPECT_GT(list1.MemoryUsageInBytes(), initial_size1);
538 EXPECT_GT(list2.MemoryUsageInBytes(), initial_size2);
539 }
540
514 TEST(ContiguousContainerTest, Alignment) { 541 TEST(ContiguousContainerTest, Alignment) {
515 const size_t max_align = ALIGNOF(long double); 542 const size_t max_align = ALIGNOF(long double);
516 ContiguousContainer<Point2D, max_align> list(kMaxPointSize); 543 ContiguousContainer<Point2D, max_align> list(kMaxPointSize);
517 544
518 list.AllocateAndConstruct<Point2D>(); 545 list.AllocateAndConstruct<Point2D>();
519 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 546 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
520 list.AllocateAndConstruct<Point2D>(); 547 list.AllocateAndConstruct<Point2D>();
521 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 548 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
522 list.AllocateAndConstruct<Point3D>(); 549 list.AllocateAndConstruct<Point3D>();
523 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 550 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
524 list.AllocateAndConstruct<Point3D>(); 551 list.AllocateAndConstruct<Point3D>();
525 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 552 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
526 list.AllocateAndConstruct<Point2D>(); 553 list.AllocateAndConstruct<Point2D>();
527 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 554 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
528 555
529 list.AppendByMoving(&list[0], sizeof(Point2D)); 556 list.AppendByMoving(&list[0], sizeof(Point2D));
530 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 557 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
531 list.AppendByMoving(&list[1], sizeof(Point2D)); 558 list.AppendByMoving(&list[1], sizeof(Point2D));
532 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 559 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
533 list.AppendByMoving(&list[2], sizeof(Point3D)); 560 list.AppendByMoving(&list[2], sizeof(Point3D));
534 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 561 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
535 list.AppendByMoving(&list[3], sizeof(Point3D)); 562 list.AppendByMoving(&list[3], sizeof(Point3D));
536 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 563 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
537 list.AppendByMoving(&list[4], sizeof(Point2D)); 564 list.AppendByMoving(&list[4], sizeof(Point2D));
538 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); 565 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1));
539 } 566 }
540 567
541 } // namespace 568 } // namespace
542 } // namespace cc 569 } // namespace cc
OLDNEW
« 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