OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Defines growable array classes, that differ where they are allocated: | 4 // Defines growable array classes, that differ where they are allocated: |
5 // - GrowableArray: allocated on stack. | 5 // - GrowableArray: allocated on stack. |
6 // - ZoneGrowableArray: allocated in the zone. | 6 // - ZoneGrowableArray: allocated in the zone. |
7 // - MallocGrowableArray: allocates using malloc/realloc; free is only called | 7 // - MallocGrowableArray: allocates using malloc/realloc; free is only called |
8 // at destruction. | 8 // at destruction. |
9 | 9 |
10 #ifndef VM_GROWABLE_ARRAY_H_ | 10 #ifndef VM_GROWABLE_ARRAY_H_ |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 template<typename T> | 155 template<typename T> |
156 class GrowableArray : public BaseGrowableArray<T, ValueObject> { | 156 class GrowableArray : public BaseGrowableArray<T, ValueObject> { |
157 public: | 157 public: |
158 GrowableArray(Zone* zone, intptr_t initial_capacity) | 158 GrowableArray(Zone* zone, intptr_t initial_capacity) |
159 : BaseGrowableArray<T, ValueObject>( | 159 : BaseGrowableArray<T, ValueObject>( |
160 initial_capacity, ASSERT_NOTNULL(zone)) {} | 160 initial_capacity, ASSERT_NOTNULL(zone)) {} |
161 explicit GrowableArray(intptr_t initial_capacity) | 161 explicit GrowableArray(intptr_t initial_capacity) |
162 : BaseGrowableArray<T, ValueObject>( | 162 : BaseGrowableArray<T, ValueObject>( |
163 initial_capacity, | 163 initial_capacity, |
164 ASSERT_NOTNULL(Isolate::Current()->current_zone())) {} | 164 ASSERT_NOTNULL(Thread::Current()->zone())) {} |
165 GrowableArray() | 165 GrowableArray() |
166 : BaseGrowableArray<T, ValueObject>( | 166 : BaseGrowableArray<T, ValueObject>( |
167 ASSERT_NOTNULL(Isolate::Current()->current_zone())) {} | 167 ASSERT_NOTNULL(Thread::Current()->zone())) {} |
168 }; | 168 }; |
169 | 169 |
170 | 170 |
171 template<typename T> | 171 template<typename T> |
172 class ZoneGrowableArray : public BaseGrowableArray<T, ZoneAllocated> { | 172 class ZoneGrowableArray : public BaseGrowableArray<T, ZoneAllocated> { |
173 public: | 173 public: |
174 ZoneGrowableArray(Zone* zone, intptr_t initial_capacity) | 174 ZoneGrowableArray(Zone* zone, intptr_t initial_capacity) |
175 : BaseGrowableArray<T, ZoneAllocated>( | 175 : BaseGrowableArray<T, ZoneAllocated>( |
176 initial_capacity, ASSERT_NOTNULL(zone)) {} | 176 initial_capacity, ASSERT_NOTNULL(zone)) {} |
177 explicit ZoneGrowableArray(intptr_t initial_capacity) | 177 explicit ZoneGrowableArray(intptr_t initial_capacity) |
178 : BaseGrowableArray<T, ZoneAllocated>( | 178 : BaseGrowableArray<T, ZoneAllocated>( |
179 initial_capacity, | 179 initial_capacity, |
180 ASSERT_NOTNULL(Isolate::Current()->current_zone())) {} | 180 ASSERT_NOTNULL(Thread::Current()->zone())) {} |
181 ZoneGrowableArray() | 181 ZoneGrowableArray() |
182 : BaseGrowableArray<T, ZoneAllocated>( | 182 : BaseGrowableArray<T, ZoneAllocated>( |
183 ASSERT_NOTNULL(Isolate::Current()->current_zone())) {} | 183 ASSERT_NOTNULL(Thread::Current()->zone())) {} |
184 }; | 184 }; |
185 | 185 |
186 | 186 |
187 class Malloc : public AllStatic { | 187 class Malloc : public AllStatic { |
188 public: | 188 public: |
189 template <class T> | 189 template <class T> |
190 static inline T* Alloc(intptr_t len) { | 190 static inline T* Alloc(intptr_t len) { |
191 return reinterpret_cast<T*>(malloc(len * sizeof(T))); | 191 return reinterpret_cast<T*>(malloc(len * sizeof(T))); |
192 } | 192 } |
193 | 193 |
(...skipping 17 matching lines...) Expand all Loading... |
211 public: | 211 public: |
212 explicit MallocGrowableArray(intptr_t initial_capacity) | 212 explicit MallocGrowableArray(intptr_t initial_capacity) |
213 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} | 213 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} |
214 MallocGrowableArray() | 214 MallocGrowableArray() |
215 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} | 215 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} |
216 }; | 216 }; |
217 | 217 |
218 } // namespace dart | 218 } // namespace dart |
219 | 219 |
220 #endif // VM_GROWABLE_ARRAY_H_ | 220 #endif // VM_GROWABLE_ARRAY_H_ |
OLD | NEW |