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

Side by Side Diff: runtime/lib/array.dart

Issue 12391046: Add List.asMap(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 9 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 | « pkg/serialization/lib/src/serialization_rule.dart ('k') | runtime/lib/byte_array.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 5
6 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
7 class _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 8
9 factory _ObjectArray(length) native "ObjectArray_allocate"; 9 factory _ObjectArray(length) native "ObjectArray_allocate";
10 10
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 228
229 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare); 229 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare);
230 230
231 List<E> toList({ bool growable: true}) { 231 List<E> toList({ bool growable: true}) {
232 return new List<E>.from(this, growable: growable); 232 return new List<E>.from(this, growable: growable);
233 } 233 }
234 234
235 Set<E> toSet() { 235 Set<E> toSet() {
236 return new Set<E>.from(this); 236 return new Set<E>.from(this);
237 } 237 }
238
239 Map<int, E> asMap() {
240 return IterableMixinWorkaround.asMapList(this);
241 }
238 } 242 }
239 243
240 244
241 // This is essentially the same class as _ObjectArray, but it does not 245 // This is essentially the same class as _ObjectArray, but it does not
242 // permit any modification of array elements from Dart code. We use 246 // permit any modification of array elements from Dart code. We use
243 // this class for arrays constructed from Dart array literals. 247 // this class for arrays constructed from Dart array literals.
244 // TODO(hausner): We should consider the trade-offs between two 248 // TODO(hausner): We should consider the trade-offs between two
245 // classes (and inline cache misses) versus a field in the native 249 // classes (and inline cache misses) versus a field in the native
246 // implementation (checks when modifying). We should keep watching 250 // implementation (checks when modifying). We should keep watching
247 // the inline cache misses. 251 // the inline cache misses.
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 471
468 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare); 472 E max([int compare(E a, E b)]) => IterableMixinWorkaround.max(this, compare);
469 473
470 List<E> toList({ bool growable: true }) { 474 List<E> toList({ bool growable: true }) {
471 return new List<E>.from(this, growable: growable); 475 return new List<E>.from(this, growable: growable);
472 } 476 }
473 477
474 Set<E> toSet() { 478 Set<E> toSet() {
475 return new Set<E>.from(this); 479 return new Set<E>.from(this);
476 } 480 }
481
482 Map<int, E> asMap() {
483 return IterableMixinWorkaround.asMapList(this);
484 }
477 } 485 }
478 486
479 487
480 // Iterator for arrays with fixed size. 488 // Iterator for arrays with fixed size.
481 class _FixedSizeArrayIterator<E> implements Iterator<E> { 489 class _FixedSizeArrayIterator<E> implements Iterator<E> {
482 final List<E> _array; 490 final List<E> _array;
483 final int _length; // Cache array length for faster access. 491 final int _length; // Cache array length for faster access.
484 int _position; 492 int _position;
485 E _current; 493 E _current;
486 494
(...skipping 11 matching lines...) Expand all
498 } 506 }
499 _position = _length; 507 _position = _length;
500 _current = null; 508 _current = null;
501 return false; 509 return false;
502 } 510 }
503 511
504 E get current { 512 E get current {
505 return _current; 513 return _current;
506 } 514 }
507 } 515 }
OLDNEW
« no previous file with comments | « pkg/serialization/lib/src/serialization_rule.dart ('k') | runtime/lib/byte_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698