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

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

Issue 397243002: Make IterableMixinWorkaround using classes return correctly typed Iterables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment, Created 6 years, 5 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
« no previous file with comments | « runtime/lib/array.dart ('k') | runtime/lib/typed_data.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 _GrowableList<T> implements List<T> { 5 class _GrowableList<T> implements List<T> {
6 6
7 void insert(int index, T element) { 7 void insert(int index, T element) {
8 if ((index < 0) || (index > length)) { 8 if ((index < 0) || (index > length)) {
9 throw new RangeError.range(index, 0, length); 9 throw new RangeError.range(index, 0, length);
10 } 10 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void removeWhere(bool test(T element)) { 70 void removeWhere(bool test(T element)) {
71 IterableMixinWorkaround.removeWhereList(this, test); 71 IterableMixinWorkaround.removeWhereList(this, test);
72 } 72 }
73 73
74 void retainWhere(bool test(T element)) { 74 void retainWhere(bool test(T element)) {
75 IterableMixinWorkaround.removeWhereList(this, 75 IterableMixinWorkaround.removeWhereList(this,
76 (T element) => !test(element)); 76 (T element) => !test(element));
77 } 77 }
78 78
79 Iterable<T> getRange(int start, int end) { 79 Iterable<T> getRange(int start, int end) {
80 return IterableMixinWorkaround.getRangeList(this, start, end); 80 return new IterableMixinWorkaround<T>().getRangeList(this, start, end);
81 } 81 }
82 82
83 void setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) { 83 void setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) {
84 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); 84 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount);
85 } 85 }
86 86
87 void removeRange(int start, int end) { 87 void removeRange(int start, int end) {
88 Lists.indicesCheck(this, start, end); 88 Lists.indicesCheck(this, start, end);
89 Lists.copy(this, end, this, start, this.length - end); 89 Lists.copy(this, end, this, start, this.length - end);
90 this.length = this.length - (end - start); 90 this.length = this.length - (end - start);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 void _grow(int new_length) { 211 void _grow(int new_length) {
212 var new_data = new _List(new_length); 212 var new_data = new _List(new_length);
213 for (int i = 0; i < length; i++) { 213 for (int i = 0; i < length; i++) {
214 new_data[i] = this[i]; 214 new_data[i] = this[i];
215 } 215 }
216 _setData(new_data); 216 _setData(new_data);
217 } 217 }
218 218
219 // Collection interface. 219 // Iterable interface.
220 220
221 bool contains(Object element) { 221 bool contains(Object element) {
222 return IterableMixinWorkaround.contains(this, element); 222 return IterableMixinWorkaround.contains(this, element);
223 } 223 }
224 224
225 void forEach(f(T element)) { 225 void forEach(f(T element)) {
226 int initialLength = length; 226 int initialLength = length;
227 for (int i = 0; i < length; i++) { 227 for (int i = 0; i < length; i++) {
228 f(this[i]); 228 f(this[i]);
229 if (length != initialLength) throw new ConcurrentModificationError(this); 229 if (length != initialLength) throw new ConcurrentModificationError(this);
(...skipping 24 matching lines...) Expand all
254 254
255 T reduce(T combine(T value, T element)) { 255 T reduce(T combine(T value, T element)) {
256 return IterableMixinWorkaround.reduce(this, combine); 256 return IterableMixinWorkaround.reduce(this, combine);
257 } 257 }
258 258
259 fold(initialValue, combine(previousValue, T element)) { 259 fold(initialValue, combine(previousValue, T element)) {
260 return IterableMixinWorkaround.fold(this, initialValue, combine); 260 return IterableMixinWorkaround.fold(this, initialValue, combine);
261 } 261 }
262 262
263 Iterable<T> where(bool f(T element)) { 263 Iterable<T> where(bool f(T element)) {
264 return IterableMixinWorkaround.where(this, f); 264 return new IterableMixinWorkaround<T>().where(this, f);
265 } 265 }
266 266
267 Iterable expand(Iterable f(T element)) { 267 Iterable expand(Iterable f(T element)) {
268 return IterableMixinWorkaround.expand(this, f); 268 return IterableMixinWorkaround.expand(this, f);
269 } 269 }
270 270
271 Iterable<T> take(int n) { 271 Iterable<T> take(int n) {
272 return IterableMixinWorkaround.takeList(this, n); 272 return new IterableMixinWorkaround<T>().takeList(this, n);
273 } 273 }
274 274
275 Iterable<T> takeWhile(bool test(T value)) { 275 Iterable<T> takeWhile(bool test(T value)) {
276 return IterableMixinWorkaround.takeWhile(this, test); 276 return new IterableMixinWorkaround<T>().takeWhile(this, test);
277 } 277 }
278 278
279 Iterable<T> skip(int n) { 279 Iterable<T> skip(int n) {
280 return IterableMixinWorkaround.skipList(this, n); 280 return new IterableMixinWorkaround<T>().skipList(this, n);
281 } 281 }
282 282
283 Iterable<T> skipWhile(bool test(T value)) { 283 Iterable<T> skipWhile(bool test(T value)) {
284 return IterableMixinWorkaround.skipWhile(this, test); 284 return new IterableMixinWorkaround<T>().skipWhile(this, test);
285 } 285 }
286 286
287 bool every(bool f(T element)) { 287 bool every(bool f(T element)) {
288 return IterableMixinWorkaround.every(this, f); 288 return IterableMixinWorkaround.every(this, f);
289 } 289 }
290 290
291 bool any(bool f(T element)) { 291 bool any(bool f(T element)) {
292 return IterableMixinWorkaround.any(this, f); 292 return IterableMixinWorkaround.any(this, f);
293 } 293 }
294 294
(...skipping 16 matching lines...) Expand all
311 bool get isEmpty { 311 bool get isEmpty {
312 return this.length == 0; 312 return this.length == 0;
313 } 313 }
314 314
315 bool get isNotEmpty => !isEmpty; 315 bool get isNotEmpty => !isEmpty;
316 316
317 void clear() { 317 void clear() {
318 this.length = 0; 318 this.length = 0;
319 } 319 }
320 320
321 Iterable<T> get reversed => IterableMixinWorkaround.reversedList(this); 321 Iterable<T> get reversed =>
322 new IterableMixinWorkaround<T>().reversedList(this);
322 323
323 void sort([int compare(T a, T b)]) { 324 void sort([int compare(T a, T b)]) {
324 IterableMixinWorkaround.sortList(this, compare); 325 IterableMixinWorkaround.sortList(this, compare);
325 } 326 }
326 327
327 void shuffle([Random random]) { 328 void shuffle([Random random]) {
328 IterableMixinWorkaround.shuffleList(this, random); 329 IterableMixinWorkaround.shuffleList(this, random);
329 } 330 }
330 331
331 String toString() => ListBase.listToString(this); 332 String toString() => ListBase.listToString(this);
332 333
333 Iterator<T> get iterator { 334 Iterator<T> get iterator {
334 return new ListIterator<T>(this); 335 return new ListIterator<T>(this);
335 } 336 }
336 337
337 List<T> toList({ bool growable: true }) { 338 List<T> toList({ bool growable: true }) {
338 return new List<T>.from(this, growable: growable); 339 return new List<T>.from(this, growable: growable);
339 } 340 }
340 341
341 Set<T> toSet() { 342 Set<T> toSet() {
342 return new Set<T>.from(this); 343 return new Set<T>.from(this);
343 } 344 }
344 345
345 Map<int, T> asMap() { 346 Map<int, T> asMap() {
346 return IterableMixinWorkaround.asMapList(this); 347 return new IterableMixinWorkaround<T>().asMapList(this);
347 } 348 }
348 } 349 }
OLDNEW
« no previous file with comments | « runtime/lib/array.dart ('k') | runtime/lib/typed_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698