Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: runtime/lib/growable_array.dart

Issue 25813002: - Rename arrays to lists: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 4
5 class _GrowableObjectArray<T> implements List<T> { 5 class _GrowableList<T> implements List<T> {
6 static final int _classId = (new _GrowableObjectArray(0))._cid; 6 static final int _classId = (new _GrowableList(0))._cid;
7 7
8 void insert(int index, T element) { 8 void insert(int index, T element) {
9 if (index < 0 || index > length) { 9 if (index < 0 || index > length) {
10 throw new RangeError.range(index, 0, length); 10 throw new RangeError.range(index, 0, length);
11 } 11 }
12 if (index == this.length) { 12 if (index == this.length) {
13 add(element); 13 add(element);
14 return; 14 return;
15 } 15 }
16 int oldLength = this.length; 16 int oldLength = this.length;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 void fillRange(int start, int end, [T fillValue]) { 111 void fillRange(int start, int end, [T fillValue]) {
112 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); 112 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue);
113 } 113 }
114 114
115 List<T> sublist(int start, [int end]) { 115 List<T> sublist(int start, [int end]) {
116 Arrays.indicesCheck(this, start, end); 116 Arrays.indicesCheck(this, start, end);
117 if (end == null) end = length; 117 if (end == null) end = length;
118 int length = end - start; 118 int length = end - start;
119 if (start == end) return <T>[]; 119 if (start == end) return <T>[];
120 List list = new _GrowableObjectArray<T>.withCapacity(length); 120 List list = new _GrowableList<T>.withCapacity(length);
121 list.length = length; 121 list.length = length;
122 Arrays.copy(this, start, list, 0, length); 122 Arrays.copy(this, start, list, 0, length);
123 return list; 123 return list;
124 } 124 }
125 125
126 factory _GrowableObjectArray(int length) { 126 factory _GrowableList(int length) {
127 var data = new _ObjectArray((length == 0) ? 4 : length); 127 var data = new _List((length == 0) ? 4 : length);
128 var result = new _GrowableObjectArray<T>.withData(data); 128 var result = new _GrowableList<T>.withData(data);
129 if (length > 0) { 129 if (length > 0) {
130 result._setLength(length); 130 result._setLength(length);
131 } 131 }
132 return result; 132 return result;
133 } 133 }
134 134
135 factory _GrowableObjectArray.withCapacity(int capacity) { 135 factory _GrowableList.withCapacity(int capacity) {
136 var data = new _ObjectArray((capacity == 0)? 4 : capacity); 136 var data = new _List((capacity == 0)? 4 : capacity);
137 return new _GrowableObjectArray<T>.withData(data); 137 return new _GrowableList<T>.withData(data);
138 } 138 }
139 139
140 factory _GrowableObjectArray.from(Iterable<T> other) { 140 factory _GrowableList.from(Iterable<T> other) {
141 List<T> result = new _GrowableObjectArray<T>(); 141 List<T> result = new _GrowableList<T>();
142 result.addAll(other); 142 result.addAll(other);
143 return result; 143 return result;
144 } 144 }
145 145
146 factory _GrowableObjectArray.withData(_ObjectArray data) 146 factory _GrowableList.withData(_List data)
147 native "GrowableObjectArray_allocate"; 147 native "GrowableList_allocate";
148 148
149 int get length native "GrowableObjectArray_getLength"; 149 int get length native "GrowableList_getLength";
150 150
151 int get _capacity native "GrowableObjectArray_getCapacity"; 151 int get _capacity native "GrowableList_getCapacity";
152 152
153 void set length(int new_length) { 153 void set length(int new_length) {
154 if (new_length > _capacity) { 154 if (new_length > _capacity) {
155 _grow(new_length); 155 _grow(new_length);
156 } else { 156 } else {
157 for (int i = new_length; i < length; i++) { 157 for (int i = new_length; i < length; i++) {
158 this[i] = null; 158 this[i] = null;
159 } 159 }
160 } 160 }
161 _setLength(new_length); 161 _setLength(new_length);
162 } 162 }
163 163
164 void _setLength(int new_length) native "GrowableObjectArray_setLength"; 164 void _setLength(int new_length) native "GrowableList_setLength";
165 165
166 void _setData(_ObjectArray array) native "GrowableObjectArray_setData"; 166 void _setData(_List array) native "GrowableList_setData";
167 167
168 T operator [](int index) native "GrowableObjectArray_getIndexed"; 168 T operator [](int index) native "GrowableList_getIndexed";
169 169
170 void operator []=(int index, T value) native "GrowableObjectArray_setIndexed"; 170 void operator []=(int index, T value) native "GrowableList_setIndexed";
171 171
172 // The length of this growable array. It is always less than or equal to the 172 // The length of this growable array. It is always less than or equal to the
173 // length of the object array, which itself is always greater than 0, so that 173 // length of the object array, which itself is always greater than 0, so that
174 // grow() does not have to check for a zero length object array before 174 // grow() does not have to check for a zero length object array before
175 // doubling its size. 175 // doubling its size.
176 void add(T value) { 176 void add(T value) {
177 var len = length; 177 var len = length;
178 if (len == _capacity) { 178 if (len == _capacity) {
179 _grow(len * 2); 179 _grow(len * 2);
180 } 180 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 214
215 int indexOf(Object element, [int start = 0]) { 215 int indexOf(Object element, [int start = 0]) {
216 return IterableMixinWorkaround.indexOfList(this, element, start); 216 return IterableMixinWorkaround.indexOfList(this, element, start);
217 } 217 }
218 218
219 int lastIndexOf(Object element, [int start = null]) { 219 int lastIndexOf(Object element, [int start = null]) {
220 return IterableMixinWorkaround.lastIndexOfList(this, element, start); 220 return IterableMixinWorkaround.lastIndexOfList(this, element, start);
221 } 221 }
222 222
223 void _grow(int new_length) { 223 void _grow(int new_length) {
224 var new_data = new _ObjectArray(new_length); 224 var new_data = new _List(new_length);
225 for (int i = 0; i < length; i++) { 225 for (int i = 0; i < length; i++) {
226 new_data[i] = this[i]; 226 new_data[i] = this[i];
227 } 227 }
228 _setData(new_data); 228 _setData(new_data);
229 } 229 }
230 230
231 // Collection interface. 231 // Collection interface.
232 232
233 bool contains(Object element) { 233 bool contains(Object element) {
234 return IterableMixinWorkaround.contains(this, element); 234 return IterableMixinWorkaround.contains(this, element);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 349 }
350 350
351 Set<T> toSet() { 351 Set<T> toSet() {
352 return new Set<T>.from(this); 352 return new Set<T>.from(this);
353 } 353 }
354 354
355 Map<int, T> asMap() { 355 Map<int, T> asMap() {
356 return IterableMixinWorkaround.asMapList(this); 356 return IterableMixinWorkaround.asMapList(this);
357 } 357 }
358 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698