| 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: allocated on stack. | 5 // - GrowableArray: allocated on stack. |
| 6 // - ZoneGrowableArray: allocated in the zone. | 6 // - ZoneGrowableArray: allocated in the zone. |
| 7 // - MallocGrowableArray: allocates using malloc/realloc; free is only called | 7 // - MallocGrowableArray: allocates using malloc/realloc; free is only called |
| 8 // at destruction. | 8 // at destruction. |
| 9 | 9 |
| 10 #ifndef VM_GROWABLE_ARRAY_H_ | 10 #ifndef VM_GROWABLE_ARRAY_H_ |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 void InsertAt(intptr_t idx, const T& value) { | 85 void InsertAt(intptr_t idx, const T& value) { |
| 86 Resize(length() + 1); | 86 Resize(length() + 1); |
| 87 for (intptr_t i = length_ - 2; i >= idx; i--) { | 87 for (intptr_t i = length_ - 2; i >= idx; i--) { |
| 88 data_[i + 1] = data_[i]; | 88 data_[i + 1] = data_[i]; |
| 89 } | 89 } |
| 90 data_[idx] = value; | 90 data_[idx] = value; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void Reverse() { |
| 94 for (intptr_t i = 0; i < length_ / 2; i++) { |
| 95 const intptr_t j = length_ - 1 - i; |
| 96 T temp = data_[i]; |
| 97 data_[i] = data_[j]; |
| 98 data_[j] = temp; |
| 99 } |
| 100 } |
| 101 |
| 93 // The content is uninitialized after calling it. | 102 // The content is uninitialized after calling it. |
| 94 void SetLength(intptr_t new_length); | 103 void SetLength(intptr_t new_length); |
| 95 | 104 |
| 96 // Sort the array in place. | 105 // Sort the array in place. |
| 97 inline void Sort(int compare(const T*, const T*)); | 106 inline void Sort(int compare(const T*, const T*)); |
| 98 | 107 |
| 99 private: | 108 private: |
| 100 intptr_t length_; | 109 intptr_t length_; |
| 101 intptr_t capacity_; | 110 intptr_t capacity_; |
| 102 T* data_; | 111 T* data_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 public: | 211 public: |
| 203 explicit MallocGrowableArray(intptr_t initial_capacity) | 212 explicit MallocGrowableArray(intptr_t initial_capacity) |
| 204 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} | 213 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} |
| 205 MallocGrowableArray() | 214 MallocGrowableArray() |
| 206 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} | 215 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} |
| 207 }; | 216 }; |
| 208 | 217 |
| 209 } // namespace dart | 218 } // namespace dart |
| 210 | 219 |
| 211 #endif // VM_GROWABLE_ARRAY_H_ | 220 #endif // VM_GROWABLE_ARRAY_H_ |
| OLD | NEW |