| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 void AddArray(const BaseGrowableArray<T, B>& src) { | 61 void AddArray(const BaseGrowableArray<T, B>& src) { |
| 62 for (int i = 0; i < src.length(); i++) { | 62 for (int i = 0; i < src.length(); i++) { |
| 63 Add(src[i]); | 63 Add(src[i]); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void Clear() { | 67 void Clear() { |
| 68 length_ = 0; | 68 length_ = 0; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RemoveFirst() { |
| 72 ASSERT(length_ > 0); |
| 73 length_--; |
| 74 for (int i = 0; i < length_; i++) { |
| 75 data_[i] = data_[i + 1]; |
| 76 } |
| 77 } |
| 78 |
| 71 // Sort the array in place. | 79 // Sort the array in place. |
| 72 inline void Sort(int compare(const T*, const T*)); | 80 inline void Sort(int compare(const T*, const T*)); |
| 73 | 81 |
| 74 private: | 82 private: |
| 75 int length_; | 83 int length_; |
| 76 int capacity_; | 84 int capacity_; |
| 77 T* data_; | 85 T* data_; |
| 78 BaseZone* zone_; // Zone in which we are allocating the array. | 86 BaseZone* zone_; // Zone in which we are allocating the array. |
| 79 | 87 |
| 80 void Resize(int new_length); | 88 void Resize(int new_length); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 initial_capacity, | 136 initial_capacity, |
| 129 Isolate::Current()->current_zone()->GetBaseZone()) {} | 137 Isolate::Current()->current_zone()->GetBaseZone()) {} |
| 130 ZoneGrowableArray() : | 138 ZoneGrowableArray() : |
| 131 BaseGrowableArray<T, ZoneAllocated>( | 139 BaseGrowableArray<T, ZoneAllocated>( |
| 132 Isolate::Current()->current_zone()->GetBaseZone()) {} | 140 Isolate::Current()->current_zone()->GetBaseZone()) {} |
| 133 }; | 141 }; |
| 134 | 142 |
| 135 } // namespace dart | 143 } // namespace dart |
| 136 | 144 |
| 137 #endif // VM_GROWABLE_ARRAY_H_ | 145 #endif // VM_GROWABLE_ARRAY_H_ |
| OLD | NEW |