OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_STACK_CONTAINER_H_ | 5 #ifndef BASE_STACK_CONTAINER_H_ |
6 #define BASE_STACK_CONTAINER_H_ | 6 #define BASE_STACK_CONTAINER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 // Casts the buffer in its right type. | 46 // Casts the buffer in its right type. |
47 T* stack_buffer() { return stack_buffer_.template data_as<T>(); } | 47 T* stack_buffer() { return stack_buffer_.template data_as<T>(); } |
48 const T* stack_buffer() const { | 48 const T* stack_buffer() const { |
49 return stack_buffer_.template data_as<T>(); | 49 return stack_buffer_.template data_as<T>(); |
50 } | 50 } |
51 | 51 |
52 // The buffer itself. It is not of type T because we don't want the | 52 // The buffer itself. It is not of type T because we don't want the |
53 // constructors and destructors to be automatically called. Define a POD | 53 // constructors and destructors to be automatically called. Define a POD |
54 // buffer of the right size instead. | 54 // buffer of the right size instead. |
55 base::AlignedMemory<sizeof(T[stack_capacity]), ALIGNOF(T)> stack_buffer_; | 55 base::AlignedMemory<sizeof(T[stack_capacity]), ALIGNOF(T)> stack_buffer_; |
56 #if defined(OS_ANDROID) | |
willchan no longer on Chromium
2012/02/28 22:31:08
Do we need to include build/build_config.h to get
jbates
2012/02/28 22:52:13
Done.
| |
57 COMPILE_ASSERT(ALIGNOF(T) <= 16, crbug_115612); | |
58 #endif | |
56 | 59 |
57 // Set when the stack buffer is used for an allocation. We do not track | 60 // Set when the stack buffer is used for an allocation. We do not track |
58 // how much of the buffer is used, only that somebody is using it. | 61 // how much of the buffer is used, only that somebody is using it. |
59 bool used_stack_buffer_; | 62 bool used_stack_buffer_; |
60 }; | 63 }; |
61 | 64 |
62 // Used by containers when they want to refer to an allocator of type U. | 65 // Used by containers when they want to refer to an allocator of type U. |
63 template<typename U> | 66 template<typename U> |
64 struct rebind { | 67 struct rebind { |
65 typedef StackAllocator<U, stack_capacity> other; | 68 typedef StackAllocator<U, stack_capacity> other; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 | 242 |
240 // Vectors are commonly indexed, which isn't very convenient even with | 243 // Vectors are commonly indexed, which isn't very convenient even with |
241 // operator-> (using "->at()" does exception stuff we don't want). | 244 // operator-> (using "->at()" does exception stuff we don't want). |
242 T& operator[](size_t i) { return this->container().operator[](i); } | 245 T& operator[](size_t i) { return this->container().operator[](i); } |
243 const T& operator[](size_t i) const { | 246 const T& operator[](size_t i) const { |
244 return this->container().operator[](i); | 247 return this->container().operator[](i); |
245 } | 248 } |
246 }; | 249 }; |
247 | 250 |
248 #endif // BASE_STACK_CONTAINER_H_ | 251 #endif // BASE_STACK_CONTAINER_H_ |
OLD | NEW |