| 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 28 matching lines...) Expand all Loading... |
| 39 void TruncateTo(intptr_t length) { | 39 void TruncateTo(intptr_t length) { |
| 40 ASSERT(length_ >= length); | 40 ASSERT(length_ >= length); |
| 41 length_ = length; | 41 length_ = length; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void Add(const T& value) { | 44 void Add(const T& value) { |
| 45 Resize(length() + 1); | 45 Resize(length() + 1); |
| 46 Last() = value; | 46 Last() = value; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void RemoveLast() { | 49 T& RemoveLast() { |
| 50 ASSERT(length_ > 0); | 50 ASSERT(length_ > 0); |
| 51 T& result = operator[](length_ - 1); |
| 51 length_--; | 52 length_--; |
| 53 return result; |
| 52 } | 54 } |
| 53 | 55 |
| 54 T& operator[](int index) const { | 56 T& operator[](int index) const { |
| 55 ASSERT(0 <= index); | 57 ASSERT(0 <= index); |
| 56 ASSERT(index < length_); | 58 ASSERT(index < length_); |
| 57 ASSERT(length_ <= capacity_); | 59 ASSERT(length_ <= capacity_); |
| 58 return data_[index]; | 60 return data_[index]; |
| 59 } | 61 } |
| 60 | 62 |
| 61 T& Last() const { | 63 T& Last() const { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 initial_capacity, | 140 initial_capacity, |
| 139 Isolate::Current()->current_zone()) {} | 141 Isolate::Current()->current_zone()) {} |
| 140 ZoneGrowableArray() : | 142 ZoneGrowableArray() : |
| 141 BaseGrowableArray<T, ZoneAllocated>( | 143 BaseGrowableArray<T, ZoneAllocated>( |
| 142 Isolate::Current()->current_zone()) {} | 144 Isolate::Current()->current_zone()) {} |
| 143 }; | 145 }; |
| 144 | 146 |
| 145 } // namespace dart | 147 } // namespace dart |
| 146 | 148 |
| 147 #endif // VM_GROWABLE_ARRAY_H_ | 149 #endif // VM_GROWABLE_ARRAY_H_ |
| OLD | NEW |