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 /** A reusable set used to identify cyclic lists during toString() calls. */ | 7 /** A reusable set used to identify cyclic lists during toString() calls. */ |
8 Set _toStringVisiting = new HashSet.identity(); | 8 Set _toStringVisiting = new HashSet.identity(); |
9 | 9 |
10 /** | 10 /** |
11 * Abstract implementation of a list. | 11 * Abstract implementation of a list. |
12 * | 12 * |
13 * All operations are defined in terms of `length`, `operator[]`, | 13 * All operations are defined in terms of `length`, `operator[]`, |
14 * `operator[]=` and `length=`, which need to be implemented. | 14 * `operator[]=` and `length=`, which need to be implemented. |
15 * | 15 * |
16 * *NOTICE*: Forwarding just these four operations to a normal growable [List] | 16 * *NOTICE*: Forwarding just these four operations to a normal growable [List] |
17 * (as created by `new List()`) will give very bad performance for `add` and | 17 * (as created by `new List()`) will give very bad performance for `add` and |
18 * `addAll` operations of `ListBase`. These operations are implemented by | 18 * `addAll` operations of `ListBase`. These operations are implemented by |
19 * increasing the length of the list by one for each `add` operation, and | 19 * increasing the length of the list by one for each `add` operation, and |
20 * repeatedly increasing the length of a growable list is not efficient. | 20 * repeatedly increasing the length of a growable list is not efficient. |
21 * To avoid this, either override 'add' and 'addAll' to also forward directly | 21 * To avoid this, either override 'add' and 'addAll' to also forward directly |
22 * to the growable list, or, preferably, use `DelegatingList` from | 22 * to the growable list, or, preferably, use `DelegatingList` from |
23 * "package:collection_helpers/wrappers.dart" instead. | 23 * "package:collection/wrappers.dart" instead. |
24 */ | 24 */ |
25 abstract class ListBase<E> = Object with ListMixin<E>; | 25 abstract class ListBase<E> = Object with ListMixin<E>; |
26 | 26 |
27 /** | 27 /** |
28 * Base implementation of a [List] class. | 28 * Base implementation of a [List] class. |
29 * | 29 * |
30 * This class can be used as a mixin. | 30 * This class can be used as a mixin. |
31 * | 31 * |
32 * This implements all read operations using only the `length` and | 32 * This implements all read operations using only the `length` and |
33 * `operator[]` members. It implements write operations using those and | 33 * `operator[]` members. It implements write operations using those and |
34 * `length=` and `operator[]=` | 34 * `length=` and `operator[]=` |
35 * | 35 * |
36 * *NOTICE*: Forwarding just these four operations to a normal growable [List] | 36 * *NOTICE*: Forwarding just these four operations to a normal growable [List] |
37 * (as created by `new List()`) will give very bad performance for `add` and | 37 * (as created by `new List()`) will give very bad performance for `add` and |
38 * `addAll` operations of `ListBase`. These operations are implemented by | 38 * `addAll` operations of `ListBase`. These operations are implemented by |
39 * increasing the length of the list by one for each `add` operation, and | 39 * increasing the length of the list by one for each `add` operation, and |
40 * repeatedly increasing the length of a growable list is not efficient. | 40 * repeatedly increasing the length of a growable list is not efficient. |
41 * To avoid this, either override 'add' and 'addAll' to also forward directly | 41 * To avoid this, either override 'add' and 'addAll' to also forward directly |
42 * to the growable list, or, if possible, use `DelegatingList` from | 42 * to the growable list, or, if possible, use `DelegatingList` from |
43 * "package:collection_helpers/wrappers.dart" instead. | 43 * "package:collection/wrappers.dart" instead. |
44 */ | 44 */ |
45 abstract class ListMixin<E> implements List<E> { | 45 abstract class ListMixin<E> implements List<E> { |
46 | 46 |
47 // Iterable interface. | 47 // Iterable interface. |
48 Iterator<E> get iterator => new ListIterator<E>(this); | 48 Iterator<E> get iterator => new ListIterator<E>(this); |
49 | 49 |
50 E elementAt(int index) => this[index]; | 50 E elementAt(int index) => this[index]; |
51 | 51 |
52 void forEach(void action(E element)) { | 52 void forEach(void action(E element)) { |
53 int length = this.length; | 53 int length = this.length; |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 result.write('['); | 535 result.write('['); |
536 result.writeAll(this, ', '); | 536 result.writeAll(this, ', '); |
537 result.write(']'); | 537 result.write(']'); |
538 } finally { | 538 } finally { |
539 _toStringVisiting.remove(this); | 539 _toStringVisiting.remove(this); |
540 } | 540 } |
541 | 541 |
542 return result.toString(); | 542 return result.toString(); |
543 } | 543 } |
544 } | 544 } |
OLD | NEW |