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

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

Issue 27308003: Document that concurrent modification is bad, m'kay. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cannot be misread as iterating changing the length. 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 17 matching lines...) Expand all
28 * growableList.add(499); 28 * growableList.add(499);
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 *
39 * It is generally not allowed to modify the list's length (adding or removing
40 * elements) while an operation on the list is being performed,
41 * for example during a call to [forEach] or [sort].
42 * Changing the list's length while it is being iterated, either by iterating it
43 * directly or through iterating an `Iterable` that is backed by the list, will
44 * break the iteration.
38 */ 45 */
39 abstract class List<E> implements Iterable<E>, EfficientLength { 46 abstract class List<E> implements Iterable<E>, EfficientLength {
40 /** 47 /**
41 * Creates a list of the given length. 48 * Creates a list of the given length.
42 * 49 *
43 * The created list is fixed-length if [length] is provided. 50 * The created list is fixed-length if [length] is provided.
44 * 51 *
45 * List fixedLengthList = new List(3); 52 * List fixedLengthList = new List(3);
46 * fixedLengthList.length; // 3 53 * fixedLengthList.length; // 3
47 fixedLengthList.length = 1; // Error 54 * fixedLengthList.length = 1; // Error
48 * 55 *
49 * 56 *
50 * The list has length 0 and is growable if [length] is omitted. 57 * The list has length 0 and is growable if [length] is omitted.
51 * 58 *
52 * List growableList = new List(); 59 * List growableList = new List();
53 * growableList.length; // 0; 60 * growableList.length; // 0;
54 * growableList.length = 3; 61 * growableList.length = 3;
55 * 62 *
56 * An error occurs if [length] is negative. 63 * An error occurs if [length] is negative.
57 */ 64 */
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 * as values. The `Map.keys` [Iterable] iterates the indices of this list 436 * as values. The `Map.keys` [Iterable] iterates the indices of this list
430 * in numerical order. 437 * in numerical order.
431 * 438 *
432 * List<String> words = ['fee', 'fi', 'fo', 'fum']; 439 * List<String> words = ['fee', 'fi', 'fo', 'fum'];
433 * Map<int, String> map = words.asMap(); 440 * Map<int, String> map = words.asMap();
434 * map[0] + map[1]; // 'feefi'; 441 * map[0] + map[1]; // 'feefi';
435 * map.keys.toList(); // [0, 1, 2, 3] 442 * map.keys.toList(); // [0, 1, 2, 3]
436 */ 443 */
437 Map<int, E> asMap(); 444 Map<int, E> asMap();
438 } 445 }
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