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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 void Swap(intptr_t i, intptr_t j) { | 103 void Swap(intptr_t i, intptr_t j) { |
104 ASSERT(i >= 0); | 104 ASSERT(i >= 0); |
105 ASSERT(j >= 0); | 105 ASSERT(j >= 0); |
106 ASSERT(i < length_); | 106 ASSERT(i < length_); |
107 ASSERT(j < length_); | 107 ASSERT(j < length_); |
108 T temp = data_[i]; | 108 T temp = data_[i]; |
109 data_[i] = data_[j]; | 109 data_[i] = data_[j]; |
110 data_[j] = temp; | 110 data_[j] = temp; |
111 } | 111 } |
112 | 112 |
113 // NOTE: Does not preserve array order. | |
114 void RemoveAt(intptr_t i) { | |
115 ASSERT(i >= 0); | |
116 ASSERT(i < length_); | |
117 if (i < length_ - 1) { | |
siva
2015/10/15 22:42:48
if (i < (length_ -1)) {
for better readability.
Cutch
2015/10/16 16:53:25
Done.
| |
118 Swap(i, length_ - 1); | |
119 } | |
120 RemoveLast(); | |
121 } | |
122 | |
113 // The content is uninitialized after calling it. | 123 // The content is uninitialized after calling it. |
114 void SetLength(intptr_t new_length); | 124 void SetLength(intptr_t new_length); |
115 | 125 |
116 // Sort the array in place. | 126 // Sort the array in place. |
117 inline void Sort(int compare(const T*, const T*)); | 127 inline void Sort(int compare(const T*, const T*)); |
118 | 128 |
119 private: | 129 private: |
120 intptr_t length_; | 130 intptr_t length_; |
121 intptr_t capacity_; | 131 intptr_t capacity_; |
122 T* data_; | 132 T* data_; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 public: | 287 public: |
278 explicit MallocGrowableArray(intptr_t initial_capacity) | 288 explicit MallocGrowableArray(intptr_t initial_capacity) |
279 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} | 289 : BaseGrowableArray<T, EmptyBase, Malloc>(initial_capacity, NULL) {} |
280 MallocGrowableArray() | 290 MallocGrowableArray() |
281 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} | 291 : BaseGrowableArray<T, EmptyBase, Malloc>(NULL) {} |
282 }; | 292 }; |
283 | 293 |
284 } // namespace dart | 294 } // namespace dart |
285 | 295 |
286 #endif // VM_GROWABLE_ARRAY_H_ | 296 #endif // VM_GROWABLE_ARRAY_H_ |
OLD | NEW |