| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.collection; | 5 part of dart.collection; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Abstract implementation of a list. | 8 * Abstract implementation of a list. |
| 9 * | 9 * |
| 10 * All operations are defined in terms of `length`, `operator[]`, | 10 * All operations are defined in terms of `length`, `operator[]`, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 * *NOTICE*: Forwarding just these four operations to a normal growable [List] | 42 * *NOTICE*: Forwarding just these four operations to a normal growable [List] |
| 43 * (as created by `new List()`) will give very bad performance for `add` and | 43 * (as created by `new List()`) will give very bad performance for `add` and |
| 44 * `addAll` operations of `ListBase`. These operations are implemented by | 44 * `addAll` operations of `ListBase`. These operations are implemented by |
| 45 * increasing the length of the list by one for each `add` operation, and | 45 * increasing the length of the list by one for each `add` operation, and |
| 46 * repeatedly increasing the length of a growable list is not efficient. | 46 * repeatedly increasing the length of a growable list is not efficient. |
| 47 * To avoid this, either override 'add' and 'addAll' to also forward directly | 47 * To avoid this, either override 'add' and 'addAll' to also forward directly |
| 48 * to the growable list, or, if possible, use `DelegatingList` from | 48 * to the growable list, or, if possible, use `DelegatingList` from |
| 49 * "package:collection/wrappers.dart" instead. | 49 * "package:collection/wrappers.dart" instead. |
| 50 */ | 50 */ |
| 51 abstract class ListMixin<E> implements List<E> { | 51 abstract class ListMixin<E> implements List<E> { |
| 52 | |
| 53 // Iterable interface. | 52 // Iterable interface. |
| 54 Iterator<E> get iterator => new ListIterator<E>(this); | 53 Iterator<E> get iterator => new ListIterator<E>(this); |
| 55 | 54 |
| 56 E elementAt(int index) => this[index]; | 55 E elementAt(int index) => this[index]; |
| 57 | 56 |
| 58 void forEach(void action(E element)) { | 57 void forEach(void action(E element)) { |
| 59 int length = this.length; | 58 int length = this.length; |
| 60 for (int i = 0; i < length; i++) { | 59 for (int i = 0; i < length; i++) { |
| 61 action(this[i]); | 60 action(this[i]); |
| 62 if (length != this.length) { | 61 if (length != this.length) { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 for (E element in iterable) { | 501 for (E element in iterable) { |
| 503 this[index++] = element; | 502 this[index++] = element; |
| 504 } | 503 } |
| 505 } | 504 } |
| 506 } | 505 } |
| 507 | 506 |
| 508 Iterable<E> get reversed => new ReversedListIterable(this); | 507 Iterable<E> get reversed => new ReversedListIterable(this); |
| 509 | 508 |
| 510 String toString() => IterableBase.iterableToFullString(this, '[', ']'); | 509 String toString() => IterableBase.iterableToFullString(this, '[', ']'); |
| 511 } | 510 } |
| OLD | NEW |