| 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 #ifndef CC_BASE_CONTIGUOUS_CONTAINER_H_ | 5 #ifndef CC_BASE_CONTIGUOUS_CONTAINER_H_ |
| 6 #define CC_BASE_CONTIGUOUS_CONTAINER_H_ | 6 #define CC_BASE_CONTIGUOUS_CONTAINER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 |
| 10 #include <memory> |
| 9 #include <utility> | 11 #include <utility> |
| 10 | 12 |
| 11 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "cc/base/cc_export.h" | 17 #include "cc/base/cc_export.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 | 20 |
| 20 // ContiguousContainer is a container which stores a list of heterogeneous | 21 // ContiguousContainer is a container which stores a list of heterogeneous |
| 21 // objects (in particular, of varying sizes), packed next to one another in | 22 // objects (in particular, of varying sizes), packed next to one another in |
| 22 // memory. Objects are never relocated, so it is safe to store pointers to them | 23 // memory. Objects are never relocated, so it is safe to store pointers to them |
| 23 // for the lifetime of the container (unless the object is removed). | 24 // for the lifetime of the container (unless the object is removed). |
| 24 // | 25 // |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 void RemoveLast(); | 54 void RemoveLast(); |
| 54 void Swap(ContiguousContainerBase& other); | 55 void Swap(ContiguousContainerBase& other); |
| 55 | 56 |
| 56 std::vector<void*> elements_; | 57 std::vector<void*> elements_; |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 class Buffer; | 60 class Buffer; |
| 60 | 61 |
| 61 Buffer* AllocateNewBufferForNextAllocation(size_t buffer_size); | 62 Buffer* AllocateNewBufferForNextAllocation(size_t buffer_size); |
| 62 | 63 |
| 63 std::vector<scoped_ptr<Buffer>> buffers_; | 64 std::vector<std::unique_ptr<Buffer>> buffers_; |
| 64 size_t end_index_; | 65 size_t end_index_; |
| 65 size_t max_object_size_; | 66 size_t max_object_size_; |
| 66 | 67 |
| 67 DISALLOW_COPY_AND_ASSIGN(ContiguousContainerBase); | 68 DISALLOW_COPY_AND_ASSIGN(ContiguousContainerBase); |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 // For most cases, no alignment stricter than pointer alignment is required. If | 71 // For most cases, no alignment stricter than pointer alignment is required. If |
| 71 // one of the derived classes has stronger alignment requirements (and the | 72 // one of the derived classes has stronger alignment requirements (and the |
| 72 // static_assert fires), set alignment to the least common multiple of the | 73 // static_assert fires), set alignment to the least common multiple of the |
| 73 // derived class alignments. For small structs without pointers, it may be | 74 // derived class alignments. For small structs without pointers, it may be |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 DCHECK_EQ(aligned_size % alignment, 0u); | 210 DCHECK_EQ(aligned_size % alignment, 0u); |
| 210 DCHECK_GE(aligned_size, size); | 211 DCHECK_GE(aligned_size, size); |
| 211 DCHECK_LT(aligned_size, size + alignment); | 212 DCHECK_LT(aligned_size, size + alignment); |
| 212 return aligned_size; | 213 return aligned_size; |
| 213 } | 214 } |
| 214 }; | 215 }; |
| 215 | 216 |
| 216 } // namespace cc | 217 } // namespace cc |
| 217 | 218 |
| 218 #endif // CC_BASE_CONTIGUOUS_CONTAINER_H_ | 219 #endif // CC_BASE_CONTIGUOUS_CONTAINER_H_ |
| OLD | NEW |