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