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: allocate on stack. | 5 // - GrowableArray: allocated on stack. |
6 // - ZoneGrowableArray: allocated in the zone. | 6 // - ZoneGrowableArray: allocated in the zone. |
7 | 7 |
8 #ifndef VM_GROWABLE_ARRAY_H_ | 8 #ifndef VM_GROWABLE_ARRAY_H_ |
9 #define VM_GROWABLE_ARRAY_H_ | 9 #define VM_GROWABLE_ARRAY_H_ |
10 | 10 |
11 #include "platform/utils.h" | 11 #include "platform/utils.h" |
12 #include "vm/allocation.h" | 12 #include "vm/allocation.h" |
13 #include "vm/isolate.h" | 13 #include "vm/isolate.h" |
14 #include "vm/zone.h" | 14 #include "vm/zone.h" |
15 | 15 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 data_ = new_data; | 115 data_ = new_data; |
116 capacity_ = new_capacity; | 116 capacity_ = new_capacity; |
117 } | 117 } |
118 length_ = new_length; | 118 length_ = new_length; |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 template<typename T> | 122 template<typename T> |
123 class GrowableArray : public BaseGrowableArray<T, ValueObject> { | 123 class GrowableArray : public BaseGrowableArray<T, ValueObject> { |
124 public: | 124 public: |
| 125 GrowableArray(Isolate* isolate, intptr_t initial_capacity) |
| 126 : BaseGrowableArray<T, ValueObject>( |
| 127 initial_capacity, isolate->current_zone()) {} |
125 explicit GrowableArray(intptr_t initial_capacity) | 128 explicit GrowableArray(intptr_t initial_capacity) |
126 : BaseGrowableArray<T, ValueObject>( | 129 : BaseGrowableArray<T, ValueObject>( |
127 initial_capacity, | 130 initial_capacity, Isolate::Current()->current_zone()) {} |
128 Isolate::Current()->current_zone()) {} | |
129 GrowableArray() | 131 GrowableArray() |
130 : BaseGrowableArray<T, ValueObject>( | 132 : BaseGrowableArray<T, ValueObject>( |
131 Isolate::Current()->current_zone()) {} | 133 Isolate::Current()->current_zone()) {} |
132 }; | 134 }; |
133 | 135 |
134 | 136 |
135 template<typename T> | 137 template<typename T> |
136 class ZoneGrowableArray : public BaseGrowableArray<T, ZoneAllocated> { | 138 class ZoneGrowableArray : public BaseGrowableArray<T, ZoneAllocated> { |
137 public: | 139 public: |
| 140 ZoneGrowableArray(Isolate* isolate, intptr_t initial_capacity) |
| 141 : BaseGrowableArray<T, ZoneAllocated>( |
| 142 initial_capacity, isolate->current_zone()) {} |
138 explicit ZoneGrowableArray(intptr_t initial_capacity) | 143 explicit ZoneGrowableArray(intptr_t initial_capacity) |
139 : BaseGrowableArray<T, ZoneAllocated>( | 144 : BaseGrowableArray<T, ZoneAllocated>( |
140 initial_capacity, | 145 initial_capacity, |
141 Isolate::Current()->current_zone()) {} | 146 Isolate::Current()->current_zone()) {} |
142 ZoneGrowableArray() : | 147 ZoneGrowableArray() : |
143 BaseGrowableArray<T, ZoneAllocated>( | 148 BaseGrowableArray<T, ZoneAllocated>( |
144 Isolate::Current()->current_zone()) {} | 149 Isolate::Current()->current_zone()) {} |
145 }; | 150 }; |
146 | 151 |
147 } // namespace dart | 152 } // namespace dart |
148 | 153 |
149 #endif // VM_GROWABLE_ARRAY_H_ | 154 #endif // VM_GROWABLE_ARRAY_H_ |
OLD | NEW |