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

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

Issue 18837002: Move toString() to collection classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | « no previous file | runtime/lib/growable_array.dart » ('j') | runtime/lib/growable_array.dart » ('J')
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 static final int _classId = (new _ObjectArray(0))._cid; 8 static final int _classId = (new _ObjectArray(0))._cid;
9
10 static List _toStringList = new List();
floitsch 2013/07/08 12:00:50 Add comment what this does.
zarah 2013/07/08 14:35:15 Done.
9 11
10 factory _ObjectArray(length) native "ObjectArray_allocate"; 12 factory _ObjectArray(length) native "ObjectArray_allocate";
11 13
12 E operator [](int index) native "ObjectArray_getIndexed"; 14 E operator [](int index) native "ObjectArray_getIndexed";
13 15
14 void operator []=(int index, E value) native "ObjectArray_setIndexed"; 16 void operator []=(int index, E value) native "ObjectArray_setIndexed";
15 17
16 String toString() { 18 String toString() {
17 return ToString.iterableToString(this); 19 for(int i = 0; i < _toStringList.length; i++) {
floitsch 2013/07/08 12:00:50 Change the call to `ToString.iterableToString` to
zarah 2013/07/08 14:35:15 Done.
20 if(identical(_toStringList[i], this))
floitsch 2013/07/08 12:00:50 Multiline `if`s always have {} for the body. You c
zarah 2013/07/08 14:35:15 Done.
21 return '[...]';
22 }
23 _toStringList.add(this);
24 String result = IterableMixinWorkaround.toStringList(this);
25 _toStringList.remove(this);
floitsch 2013/07/08 12:00:50 You need to guard the removal with a `finally`. (A
zarah 2013/07/08 14:35:15 Done.
26 return result;
18 } 27 }
19 28
20 int get length native "ObjectArray_getLength"; 29 int get length native "ObjectArray_getLength";
21 30
22 void _copyFromObjectArray(_ObjectArray src, 31 void _copyFromObjectArray(_ObjectArray src,
23 int srcStart, 32 int srcStart,
24 int dstStart, 33 int dstStart,
25 int count) 34 int count)
26 native "ObjectArray_copyFromObjectArray"; 35 native "ObjectArray_copyFromObjectArray";
27 36
28 void insert(int index, E element) { 37 void insert(int index, E element) {
29 throw new UnsupportedError( 38 throw new UnsupportedError(
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 281
273 // This is essentially the same class as _ObjectArray, but it does not 282 // This is essentially the same class as _ObjectArray, but it does not
274 // permit any modification of array elements from Dart code. We use 283 // permit any modification of array elements from Dart code. We use
275 // this class for arrays constructed from Dart array literals. 284 // this class for arrays constructed from Dart array literals.
276 // TODO(hausner): We should consider the trade-offs between two 285 // TODO(hausner): We should consider the trade-offs between two
277 // classes (and inline cache misses) versus a field in the native 286 // classes (and inline cache misses) versus a field in the native
278 // implementation (checks when modifying). We should keep watching 287 // implementation (checks when modifying). We should keep watching
279 // the inline cache misses. 288 // the inline cache misses.
280 class _ImmutableArray<E> implements List<E> { 289 class _ImmutableArray<E> implements List<E> {
281 static final int _classId = (const [])._cid; 290 static final int _classId = (const [])._cid;
291 static List _toStringList = new List();
282 292
283 factory _ImmutableArray._uninstantiable() { 293 factory _ImmutableArray._uninstantiable() {
284 throw new UnsupportedError( 294 throw new UnsupportedError(
285 "ImmutableArray can only be allocated by the VM"); 295 "ImmutableArray can only be allocated by the VM");
286 } 296 }
287 297
288 E operator [](int index) native "ObjectArray_getIndexed"; 298 E operator [](int index) native "ObjectArray_getIndexed";
289 299
290 void operator []=(int index, E value) { 300 void operator []=(int index, E value) {
291 throw new UnsupportedError( 301 throw new UnsupportedError(
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 459
450 bool get isNotEmpty => !isEmpty; 460 bool get isNotEmpty => !isEmpty;
451 461
452 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this); 462 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this);
453 463
454 void sort([int compare(E a, E b)]) { 464 void sort([int compare(E a, E b)]) {
455 throw new UnsupportedError( 465 throw new UnsupportedError(
456 "Cannot modify an immutable array"); 466 "Cannot modify an immutable array");
457 } 467 }
458 468
459 String toString() { 469 String toString() {
floitsch 2013/07/08 12:00:50 As above. Change to IterableMixinWorkaround.toStri
zarah 2013/07/08 14:35:15 Done.
460 return ToString.iterableToString(this); 470 for(int i = 0; i < _toStringList.length; i++) {
471 if(identical(_toStringList[i], this))
472 return '[...]';
473 }
474 _toStringList.add(this);
475 String result = IterableMixinWorkaround.toStringList(this);
476 _toStringList.remove(this);
477 return result;
461 } 478 }
462 479
463 int indexOf(Object element, [int start = 0]) { 480 int indexOf(Object element, [int start = 0]) {
464 return Arrays.indexOf(this, element, start, this.length); 481 return Arrays.indexOf(this, element, start, this.length);
465 } 482 }
466 483
467 int lastIndexOf(Object element, [int start = null]) { 484 int lastIndexOf(Object element, [int start = null]) {
468 if (start == null) start = length - 1; 485 if (start == null) start = length - 1;
469 return Arrays.lastIndexOf(this, element, start); 486 return Arrays.lastIndexOf(this, element, start);
470 } 487 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 566 }
550 _position = _length; 567 _position = _length;
551 _current = null; 568 _current = null;
552 return false; 569 return false;
553 } 570 }
554 571
555 E get current { 572 E get current {
556 return _current; 573 return _current;
557 } 574 }
558 } 575 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/growable_array.dart » ('j') | runtime/lib/growable_array.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698