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: allocate 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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 if (initial_capacity > 0) { | 29 if (initial_capacity > 0) { |
30 capacity_ = Utils::RoundUpToPowerOfTwo(initial_capacity); | 30 capacity_ = Utils::RoundUpToPowerOfTwo(initial_capacity); |
31 data_ = reinterpret_cast<T*>(zone_->Allocate(capacity_ * sizeof(T))); | 31 data_ = reinterpret_cast<T*>(zone_->Allocate(capacity_ * sizeof(T))); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 int length() const { return length_; } | 35 int length() const { return length_; } |
36 T* data() const { return data_; } | 36 T* data() const { return data_; } |
37 bool is_empty() const { return length_ == 0; } | 37 bool is_empty() const { return length_ == 0; } |
38 | 38 |
| 39 void TruncateTo(intptr_t length) { |
| 40 ASSERT(length_ >= length); |
| 41 length_ = length; |
| 42 } |
| 43 |
39 void Add(const T& value) { | 44 void Add(const T& value) { |
40 Resize(length() + 1); | 45 Resize(length() + 1); |
41 Last() = value; | 46 Last() = value; |
42 } | 47 } |
43 | 48 |
44 void RemoveLast() { | 49 void RemoveLast() { |
45 ASSERT(length_ > 0); | 50 ASSERT(length_ > 0); |
46 length_--; | 51 length_--; |
47 } | 52 } |
48 | 53 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 initial_capacity, | 149 initial_capacity, |
145 Isolate::Current()->current_zone()->GetBaseZone()) {} | 150 Isolate::Current()->current_zone()->GetBaseZone()) {} |
146 ZoneGrowableArray() : | 151 ZoneGrowableArray() : |
147 BaseGrowableArray<T, ZoneAllocated>( | 152 BaseGrowableArray<T, ZoneAllocated>( |
148 Isolate::Current()->current_zone()->GetBaseZone()) {} | 153 Isolate::Current()->current_zone()->GetBaseZone()) {} |
149 }; | 154 }; |
150 | 155 |
151 } // namespace dart | 156 } // namespace dart |
152 | 157 |
153 #endif // VM_GROWABLE_ARRAY_H_ | 158 #endif // VM_GROWABLE_ARRAY_H_ |
OLD | NEW |