OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_CONTAINERS_STACK_CONTAINER_H_ | 5 #ifndef BASE_CONTAINERS_STACK_CONTAINER_H_ |
6 #define BASE_CONTAINERS_STACK_CONTAINER_H_ | 6 #define BASE_CONTAINERS_STACK_CONTAINER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 // Casts the buffer in its right type. | 51 // Casts the buffer in its right type. |
52 T* stack_buffer() { return stack_buffer_.template data_as<T>(); } | 52 T* stack_buffer() { return stack_buffer_.template data_as<T>(); } |
53 const T* stack_buffer() const { | 53 const T* stack_buffer() const { |
54 return stack_buffer_.template data_as<T>(); | 54 return stack_buffer_.template data_as<T>(); |
55 } | 55 } |
56 | 56 |
57 // The buffer itself. It is not of type T because we don't want the | 57 // The buffer itself. It is not of type T because we don't want the |
58 // constructors and destructors to be automatically called. Define a POD | 58 // constructors and destructors to be automatically called. Define a POD |
59 // buffer of the right size instead. | 59 // buffer of the right size instead. |
60 base::AlignedMemory<sizeof(T[stack_capacity]), ALIGNOF(T)> stack_buffer_; | 60 base::AlignedMemory<sizeof(T[stack_capacity]), alignof(T)> stack_buffer_; |
61 #if defined(__GNUC__) && !defined(ARCH_CPU_X86_FAMILY) | 61 #if defined(__GNUC__) && !defined(ARCH_CPU_X86_FAMILY) |
62 static_assert(ALIGNOF(T) <= 16, "http://crbug.com/115612"); | 62 static_assert(alignof(T) <= 16, "http://crbug.com/115612"); |
63 #endif | 63 #endif |
64 | 64 |
65 // Set when the stack buffer is used for an allocation. We do not track | 65 // Set when the stack buffer is used for an allocation. We do not track |
66 // how much of the buffer is used, only that somebody is using it. | 66 // how much of the buffer is used, only that somebody is using it. |
67 bool used_stack_buffer_; | 67 bool used_stack_buffer_; |
68 }; | 68 }; |
69 | 69 |
70 // Used by containers when they want to refer to an allocator of type U. | 70 // Used by containers when they want to refer to an allocator of type U. |
71 template<typename U> | 71 template<typename U> |
72 struct rebind { | 72 struct rebind { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // operator-> (using "->at()" does exception stuff we don't want). | 259 // operator-> (using "->at()" does exception stuff we don't want). |
260 T& operator[](size_t i) { return this->container().operator[](i); } | 260 T& operator[](size_t i) { return this->container().operator[](i); } |
261 const T& operator[](size_t i) const { | 261 const T& operator[](size_t i) const { |
262 return this->container().operator[](i); | 262 return this->container().operator[](i); |
263 } | 263 } |
264 }; | 264 }; |
265 | 265 |
266 } // namespace base | 266 } // namespace base |
267 | 267 |
268 #endif // BASE_CONTAINERS_STACK_CONTAINER_H_ | 268 #endif // BASE_CONTAINERS_STACK_CONTAINER_H_ |
OLD | NEW |