| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 void Reverse() { | 93 void Reverse() { |
| 94 for (intptr_t i = 0; i < length_ / 2; i++) { | 94 for (intptr_t i = 0; i < length_ / 2; i++) { |
| 95 const intptr_t j = length_ - 1 - i; | 95 const intptr_t j = length_ - 1 - i; |
| 96 T temp = data_[i]; | 96 T temp = data_[i]; |
| 97 data_[i] = data_[j]; | 97 data_[i] = data_[j]; |
| 98 data_[j] = temp; | 98 data_[j] = temp; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Swap entries |i| and |j|. |
| 103 void Swap(intptr_t i, intptr_t j) { |
| 104 ASSERT(i >= 0); |
| 105 ASSERT(j >= 0); |
| 106 ASSERT(i < length_); |
| 107 ASSERT(j < length_); |
| 108 T temp = data_[i]; |
| 109 data_[i] = data_[j]; |
| 110 data_[j] = temp; |
| 111 } |
| 112 |
| 102 // The content is uninitialized after calling it. | 113 // The content is uninitialized after calling it. |
| 103 void SetLength(intptr_t new_length); | 114 void SetLength(intptr_t new_length); |
| 104 | 115 |
| 105 // Sort the array in place. | 116 // Sort the array in place. |
| 106 inline void Sort(int compare(const T*, const T*)); | 117 inline void Sort(int compare(const T*, const T*)); |
| 107 | 118 |
| 108 private: | 119 private: |
| 109 intptr_t length_; | 120 intptr_t length_; |
| 110 intptr_t capacity_; | 121 intptr_t capacity_; |
| 111 T* data_; | 122 T* data_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 public: | 222 public: |
| 212 explicit MallocGrowableArray(intptr_t initial_capacity) | 223 explicit MallocGrowableArray(intptr_t initial_capacity) |
| 213 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} | 224 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} |
| 214 MallocGrowableArray() | 225 MallocGrowableArray() |
| 215 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} | 226 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} |
| 216 }; | 227 }; |
| 217 | 228 |
| 218 } // namespace dart | 229 } // namespace dart |
| 219 | 230 |
| 220 #endif // VM_GROWABLE_ARRAY_H_ | 231 #endif // VM_GROWABLE_ARRAY_H_ |
| OLD | NEW |