| OLD | NEW |
| 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 <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "cc/base/contiguous_container.h" | 9 #include "cc/base/contiguous_container.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 for (auto it = list.rbegin(); it != list.rend(); ++it) { | 154 for (auto it = list.rbegin(); it != list.rend(); ++it) { |
| 155 EXPECT_EQ((int)(kNumElements - 1 - count), it->x); | 155 EXPECT_EQ((int)(kNumElements - 1 - count), it->x); |
| 156 count++; | 156 count++; |
| 157 } | 157 } |
| 158 EXPECT_EQ(kNumElements, count); | 158 EXPECT_EQ(kNumElements, count); |
| 159 | 159 |
| 160 static_assert(std::is_same<decltype(*list.rbegin()), Point2D&>::value, | 160 static_assert(std::is_same<decltype(*list.rbegin()), Point2D&>::value, |
| 161 "Non-const iteration should produce non-const references."); | 161 "Non-const iteration should produce non-const references."); |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Checks that the latter list has pointers to the elements of the former. | |
| 165 template <typename It1, typename It2> | |
| 166 bool EqualPointers(It1 it1, const It1& end1, It2 it2) { | |
| 167 for (; it1 != end1; ++it1, ++it2) { | |
| 168 if (&*it1 != *it2) | |
| 169 return false; | |
| 170 } | |
| 171 return true; | |
| 172 } | |
| 173 | |
| 174 TEST(ContiguousContainerTest, CapacityInBytes) { | 164 TEST(ContiguousContainerTest, CapacityInBytes) { |
| 175 const int iterations = 500; | 165 const int iterations = 500; |
| 176 const size_t initial_capacity = 10 * kMaxPointSize; | 166 const size_t initial_capacity = 10 * kMaxPointSize; |
| 177 const size_t upper_bound_on_min_capacity = initial_capacity; | 167 const size_t upper_bound_on_min_capacity = initial_capacity; |
| 178 | 168 |
| 179 // At time of writing, removing elements from the end can cause up to 7x the | 169 // At time of writing, removing elements from the end can cause up to 7x the |
| 180 // memory required to be consumed, in the worst case, since we can have up to | 170 // memory required to be consumed, in the worst case, since we can have up to |
| 181 // two trailing inner lists that are empty (for 2*size + 4*size in unused | 171 // two trailing inner lists that are empty (for 2*size + 4*size in unused |
| 182 // memory, due to the exponential growth strategy). | 172 // memory, due to the exponential growth strategy). |
| 183 // Unfortunately, this captures behaviour of the underlying allocator as | 173 // Unfortunately, this captures behaviour of the underlying allocator as |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 list.AllocateAndConstruct<Point3D>(); | 226 list.AllocateAndConstruct<Point3D>(); |
| 237 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 227 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
| 238 list.AllocateAndConstruct<Point3D>(); | 228 list.AllocateAndConstruct<Point3D>(); |
| 239 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 229 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
| 240 list.AllocateAndConstruct<Point2D>(); | 230 list.AllocateAndConstruct<Point2D>(); |
| 241 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); | 231 EXPECT_EQ(0u, reinterpret_cast<intptr_t>(&list.last()) & (max_align - 1)); |
| 242 } | 232 } |
| 243 | 233 |
| 244 } // namespace | 234 } // namespace |
| 245 } // namespace cc | 235 } // namespace cc |
| OLD | NEW |