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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/growable_array.dart » ('j') | runtime/lib/growable_array.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/array.dart
diff --git a/runtime/lib/array.dart b/runtime/lib/array.dart
index e7f88a3ddb70525e20e355a8f54c50925bee8165..61430ad8992266aeae840cacaef29d23ca0d2040 100644
--- a/runtime/lib/array.dart
+++ b/runtime/lib/array.dart
@@ -6,6 +6,8 @@
// TODO(srdjan): Use shared array implementation.
class _ObjectArray<E> implements List<E> {
static final int _classId = (new _ObjectArray(0))._cid;
+
+ 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.
factory _ObjectArray(length) native "ObjectArray_allocate";
@@ -14,9 +16,16 @@ class _ObjectArray<E> implements List<E> {
void operator []=(int index, E value) native "ObjectArray_setIndexed";
String toString() {
- return ToString.iterableToString(this);
+ 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.
+ 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.
+ return '[...]';
+ }
+ _toStringList.add(this);
+ String result = IterableMixinWorkaround.toStringList(this);
+ _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.
+ return result;
}
-
+
int get length native "ObjectArray_getLength";
void _copyFromObjectArray(_ObjectArray src,
@@ -279,6 +288,7 @@ class _ObjectArray<E> implements List<E> {
// the inline cache misses.
class _ImmutableArray<E> implements List<E> {
static final int _classId = (const [])._cid;
+ static List _toStringList = new List();
factory _ImmutableArray._uninstantiable() {
throw new UnsupportedError(
@@ -457,7 +467,14 @@ class _ImmutableArray<E> implements List<E> {
}
String toString() {
floitsch 2013/07/08 12:00:50 As above. Change to IterableMixinWorkaround.toStri
zarah 2013/07/08 14:35:15 Done.
- return ToString.iterableToString(this);
+ for(int i = 0; i < _toStringList.length; i++) {
+ if(identical(_toStringList[i], this))
+ return '[...]';
+ }
+ _toStringList.add(this);
+ String result = IterableMixinWorkaround.toStringList(this);
+ _toStringList.remove(this);
+ return result;
}
int indexOf(Object element, [int start = 0]) {
« 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