| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 void AddArray(const BaseGrowableArray<T, B>& src) { | 66 void AddArray(const BaseGrowableArray<T, B>& src) { |
| 67 for (intptr_t i = 0; i < src.length(); i++) { | 67 for (intptr_t i = 0; i < src.length(); i++) { |
| 68 Add(src[i]); | 68 Add(src[i]); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 void Clear() { | 72 void Clear() { |
| 73 length_ = 0; | 73 length_ = 0; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void RemoveFirst() { |
| 77 ASSERT(length_ > 0); |
| 78 length_--; |
| 79 for (int i = 0; i < length_; i++) { |
| 80 data_[i] = data_[i + 1]; |
| 81 } |
| 82 } |
| 83 |
| 76 void InsertAt(intptr_t idx, const T& value) { | 84 void InsertAt(intptr_t idx, const T& value) { |
| 77 Resize(length() + 1); | 85 Resize(length() + 1); |
| 78 for (intptr_t i = length_ - 2; i >= idx; i--) { | 86 for (intptr_t i = length_ - 2; i >= idx; i--) { |
| 79 data_[i + 1] = data_[i]; | 87 data_[i + 1] = data_[i]; |
| 80 } | 88 } |
| 81 data_[idx] = value; | 89 data_[idx] = value; |
| 82 } | 90 } |
| 83 | 91 |
| 84 // Sort the array in place. | 92 // Sort the array in place. |
| 85 inline void Sort(int compare(const T*, const T*)); | 93 inline void Sort(int compare(const T*, const T*)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 initial_capacity, | 146 initial_capacity, |
| 139 Isolate::Current()->current_zone()->GetBaseZone()) {} | 147 Isolate::Current()->current_zone()->GetBaseZone()) {} |
| 140 ZoneGrowableArray() : | 148 ZoneGrowableArray() : |
| 141 BaseGrowableArray<T, ZoneAllocated>( | 149 BaseGrowableArray<T, ZoneAllocated>( |
| 142 Isolate::Current()->current_zone()->GetBaseZone()) {} | 150 Isolate::Current()->current_zone()->GetBaseZone()) {} |
| 143 }; | 151 }; |
| 144 | 152 |
| 145 } // namespace dart | 153 } // namespace dart |
| 146 | 154 |
| 147 #endif // VM_GROWABLE_ARRAY_H_ | 155 #endif // VM_GROWABLE_ARRAY_H_ |
| OLD | NEW |