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

Side by Side Diff: sdk/lib/collection/iterable.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/_internal/lib/constant_map.dart ('k') | sdk/lib/collection/list.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.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * This [Iterable] mixin implements all [Iterable] members except `iterator`. 8 * This [Iterable] mixin implements all [Iterable] members except `iterator`.
9 * 9 *
10 * All other methods are implemented in terms of `iterator`. 10 * All other methods are implemented in terms of `iterator`.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 return false; 79 return false;
80 } 80 }
81 81
82 List<E> toList({ bool growable: true }) => 82 List<E> toList({ bool growable: true }) =>
83 new List<E>.from(this, growable: growable); 83 new List<E>.from(this, growable: growable);
84 84
85 Set<E> toSet() => new Set<E>.from(this); 85 Set<E> toSet() => new Set<E>.from(this);
86 86
87 int get length { 87 int get length {
88 assert(this is! EfficientLength);
88 int count = 0; 89 int count = 0;
89 Iterator it = iterator; 90 Iterator it = iterator;
90 while (it.moveNext()) { 91 while (it.moveNext()) {
91 count++; 92 count++;
92 } 93 }
93 return count; 94 return count;
94 } 95 }
95 96
96 bool get isEmpty => !iterator.moveNext(); 97 bool get isEmpty => !iterator.moveNext();
97 98
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 270 }
270 return false; 271 return false;
271 } 272 }
272 273
273 List<E> toList({ bool growable: true }) => 274 List<E> toList({ bool growable: true }) =>
274 new List<E>.from(this, growable: growable); 275 new List<E>.from(this, growable: growable);
275 276
276 Set<E> toSet() => new Set<E>.from(this); 277 Set<E> toSet() => new Set<E>.from(this);
277 278
278 int get length { 279 int get length {
280 assert(this is! EfficientLength);
279 int count = 0; 281 int count = 0;
280 Iterator it = iterator; 282 Iterator it = iterator;
281 while (it.moveNext()) { 283 while (it.moveNext()) {
282 count++; 284 count++;
283 } 285 }
284 return count; 286 return count;
285 } 287 }
286 288
287 bool get isEmpty => !iterator.moveNext(); 289 bool get isEmpty => !iterator.moveNext();
288 290
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 E elementAt(int index) { 375 E elementAt(int index) {
374 if (index is! int || index < 0) throw new RangeError.value(index); 376 if (index is! int || index < 0) throw new RangeError.value(index);
375 int remaining = index; 377 int remaining = index;
376 for (E element in this) { 378 for (E element in this) {
377 if (remaining == 0) return element; 379 if (remaining == 0) return element;
378 remaining--; 380 remaining--;
379 } 381 }
380 throw new RangeError.value(index); 382 throw new RangeError.value(index);
381 } 383 }
382 } 384 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/lib/constant_map.dart ('k') | sdk/lib/collection/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698