Chromium Code Reviews| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 } | 82 } |
| 83 | 83 |
| 84 void InsertAt(intptr_t idx, const T& value) { | 84 void InsertAt(intptr_t idx, const T& value) { |
| 85 Resize(length() + 1); | 85 Resize(length() + 1); |
| 86 for (intptr_t i = length_ - 2; i >= idx; i--) { | 86 for (intptr_t i = length_ - 2; i >= idx; i--) { |
| 87 data_[i + 1] = data_[i]; | 87 data_[i + 1] = data_[i]; |
| 88 } | 88 } |
| 89 data_[idx] = value; | 89 data_[idx] = value; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool Contains(const T& value) { | |
|
Kevin Millikin (Google)
2012/09/06 12:42:42
I actually like not having this function defined :
Florian Schneider
2012/09/06 13:05:53
Done.
| |
| 93 for (intptr_t i = 0; i < length(); i++) { | |
| 94 if (data_[i] == value) { | |
| 95 return true; | |
| 96 } | |
| 97 } | |
| 98 return false; | |
| 99 } | |
| 100 | |
| 92 // Sort the array in place. | 101 // Sort the array in place. |
| 93 inline void Sort(int compare(const T*, const T*)); | 102 inline void Sort(int compare(const T*, const T*)); |
| 94 | 103 |
| 95 private: | 104 private: |
| 96 int length_; | 105 int length_; |
| 97 int capacity_; | 106 int capacity_; |
| 98 T* data_; | 107 T* data_; |
| 99 BaseZone* zone_; // Zone in which we are allocating the array. | 108 BaseZone* zone_; // Zone in which we are allocating the array. |
| 100 | 109 |
| 101 void Resize(int new_length); | 110 void Resize(int new_length); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 initial_capacity, | 155 initial_capacity, |
| 147 Isolate::Current()->current_zone()->GetBaseZone()) {} | 156 Isolate::Current()->current_zone()->GetBaseZone()) {} |
| 148 ZoneGrowableArray() : | 157 ZoneGrowableArray() : |
| 149 BaseGrowableArray<T, ZoneAllocated>( | 158 BaseGrowableArray<T, ZoneAllocated>( |
| 150 Isolate::Current()->current_zone()->GetBaseZone()) {} | 159 Isolate::Current()->current_zone()->GetBaseZone()) {} |
| 151 }; | 160 }; |
| 152 | 161 |
| 153 } // namespace dart | 162 } // namespace dart |
| 154 | 163 |
| 155 #endif // VM_GROWABLE_ARRAY_H_ | 164 #endif // VM_GROWABLE_ARRAY_H_ |
| OLD | NEW |