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

Side by Side Diff: sdk/lib/core/list.dart

Issue 26681002: Add EfficientLength marker interface to some iterabels. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also document Map.length is efficient, while we are at it. 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
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | sdk/lib/core/map.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 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * An indexable collection of objects with a length. 8 * An indexable collection of objects with a length.
9 * 9 *
10 * Subclasses of this class implement different kinds of lists. 10 * Subclasses of this class implement different kinds of lists.
(...skipping 18 matching lines...) Expand all
29 * growableList[0] = 87; 29 * growableList[0] = 87;
30 * 30 *
31 * Lists are [Iterable]. Iteration occurs over values in index order. Changing 31 * Lists are [Iterable]. Iteration occurs over values in index order. Changing
32 * the values does not affect iteration, but changing the valid 32 * the values does not affect iteration, but changing the valid
33 * indices—that is, changing the list's length—between iteration 33 * indices—that is, changing the list's length—between iteration
34 * steps causes a [ConcurrentModificationError]. This means that only growable 34 * steps causes a [ConcurrentModificationError]. This means that only growable
35 * lists can throw ConcurrentModificationError. If the length changes 35 * lists can throw ConcurrentModificationError. If the length changes
36 * temporarily and is restored before continuing the iteration, the iterator 36 * temporarily and is restored before continuing the iteration, the iterator
37 * does not detect it. 37 * does not detect it.
38 */ 38 */
39 abstract class List<E> implements Iterable<E> { 39 abstract class List<E> implements Iterable<E>, EfficientLength {
40 /** 40 /**
41 * Creates a list of the given length. 41 * Creates a list of the given length.
42 * 42 *
43 * The created list is fixed-length if [length] is provided. 43 * The created list is fixed-length if [length] is provided.
44 * 44 *
45 * List fixedLengthList = new List(3); 45 * List fixedLengthList = new List(3);
46 * fixedLengthList.length; // 3 46 * fixedLengthList.length; // 3
47 fixedLengthList.length = 1; // Error 47 fixedLengthList.length = 1; // Error
48 * 48 *
49 * 49 *
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 /** 121 /**
122 * Sets the value at the given [index] in the list to [value] 122 * Sets the value at the given [index] in the list to [value]
123 * or throws a [RangeError] if [index] is out of bounds. 123 * or throws a [RangeError] if [index] is out of bounds.
124 */ 124 */
125 void operator []=(int index, E value); 125 void operator []=(int index, E value);
126 126
127 /** 127 /**
128 * Returns the number of objects in this list. 128 * Returns the number of objects in this list.
129 * 129 *
130 * The valid indices for a list are `0` through `length - 1`. 130 * The valid indices for a list are `0` through `length - 1`.
131 *
132 * This operations is efficient, and does not require iterating and counting
133 * the elements.
131 */ 134 */
132 int get length; 135 int get length;
133 136
134 /** 137 /**
135 * Changes the length of this list. 138 * Changes the length of this list.
136 * 139 *
137 * If [newLength] is greater than 140 * If [newLength] is greater than
138 * the current length, entries are initialized to [:null:]. 141 * the current length, entries are initialized to [:null:].
139 * 142 *
140 * Throws an [UnsupportedError] if the list is fixed-length. 143 * Throws an [UnsupportedError] if the list is fixed-length.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 * as values. The `Map.keys` [Iterable] iterates the indices of this list 432 * as values. The `Map.keys` [Iterable] iterates the indices of this list
430 * in numerical order. 433 * in numerical order.
431 * 434 *
432 * List<String> words = ['fee', 'fi', 'fo', 'fum']; 435 * List<String> words = ['fee', 'fi', 'fo', 'fum'];
433 * Map<int, String> map = words.asMap(); 436 * Map<int, String> map = words.asMap();
434 * map[0] + map[1]; // 'feefi'; 437 * map[0] + map[1]; // 'feefi';
435 * map.keys.toList(); // [0, 1, 2, 3] 438 * map.keys.toList(); // [0, 1, 2, 3]
436 */ 439 */
437 Map<int, E> asMap(); 440 Map<int, E> asMap();
438 } 441 }
OLDNEW
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | sdk/lib/core/map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698