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 | 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 return result; | 53 return result; |
54 } | 54 } |
55 | 55 |
56 T& operator[](intptr_t index) const { | 56 T& operator[](intptr_t index) const { |
57 ASSERT(0 <= index); | 57 ASSERT(0 <= index); |
58 ASSERT(index < length_); | 58 ASSERT(index < length_); |
59 ASSERT(length_ <= capacity_); | 59 ASSERT(length_ <= capacity_); |
60 return data_[index]; | 60 return data_[index]; |
61 } | 61 } |
62 | 62 |
63 const T& At(intptr_t index) const { | |
64 return operator[](index); | |
65 } | |
66 | |
67 T& Last() const { | 63 T& Last() const { |
68 ASSERT(length_ > 0); | 64 ASSERT(length_ > 0); |
69 return operator[](length_ - 1); | 65 return operator[](length_ - 1); |
70 } | 66 } |
71 | 67 |
72 void AddArray(const BaseGrowableArray<T, B>& src) { | 68 void AddArray(const BaseGrowableArray<T, B>& src) { |
73 for (intptr_t i = 0; i < src.length(); i++) { | 69 for (intptr_t i = 0; i < src.length(); i++) { |
74 Add(src[i]); | 70 Add(src[i]); |
75 } | 71 } |
76 } | 72 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 initial_capacity, | 161 initial_capacity, |
166 Isolate::Current()->current_zone()) {} | 162 Isolate::Current()->current_zone()) {} |
167 ZoneGrowableArray() : | 163 ZoneGrowableArray() : |
168 BaseGrowableArray<T, ZoneAllocated>( | 164 BaseGrowableArray<T, ZoneAllocated>( |
169 Isolate::Current()->current_zone()) {} | 165 Isolate::Current()->current_zone()) {} |
170 }; | 166 }; |
171 | 167 |
172 } // namespace dart | 168 } // namespace dart |
173 | 169 |
174 #endif // VM_GROWABLE_ARRAY_H_ | 170 #endif // VM_GROWABLE_ARRAY_H_ |
OLD | NEW |