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

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

Issue 1214723009: Make List constructor give better error messages for non-int arguments (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Merge to head. Created 5 years, 4 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
OLDNEW
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 * `ListBase` can be used as a base class for implementing the `List` interface. 10 * `ListBase` can be used as a base class for implementing the `List` interface.
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 return result; 238 return result;
239 } 239 }
240 240
241 // Collection interface. 241 // Collection interface.
242 void add(E element) { 242 void add(E element) {
243 this[this.length++] = element; 243 this[this.length++] = element;
244 } 244 }
245 245
246 void addAll(Iterable<E> iterable) { 246 void addAll(Iterable<E> iterable) {
247 int i = this.length;
247 for (E element in iterable) { 248 for (E element in iterable) {
248 this[this.length++] = element; 249 assert(this.length == i || (throw new ConcurrentModificationError(this)));
srdjan 2015/08/14 18:00:55 What is the rule with COncurrentModificationErrors
Lasse Reichstein Nielsen 2015/08/14 22:11:01 There is no rule as such. We have made them checke
250 this.length = i + 1;
251 this[i] = element;
252 i++;
249 } 253 }
250 } 254 }
251 255
252 bool remove(Object element) { 256 bool remove(Object element) {
253 for (int i = 0; i < this.length; i++) { 257 for (int i = 0; i < this.length; i++) {
254 if (this[i] == element) { 258 if (this[i] == element) {
255 this.setRange(i, this.length - 1, this, i + 1); 259 this.setRange(i, this.length - 1, this, i + 1);
256 this.length -= 1; 260 this.length -= 1;
257 return true; 261 return true;
258 } 262 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 for (E element in iterable) { 505 for (E element in iterable) {
502 this[index++] = element; 506 this[index++] = element;
503 } 507 }
504 } 508 }
505 } 509 }
506 510
507 Iterable<E> get reversed => new ReversedListIterable<E>(this); 511 Iterable<E> get reversed => new ReversedListIterable<E>(this);
508 512
509 String toString() => IterableBase.iterableToFullString(this, '[', ']'); 513 String toString() => IterableBase.iterableToFullString(this, '[', ']');
510 } 514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698