Chromium Code Reviews| Index: sdk/lib/collection/list.dart |
| diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart |
| index 5c81ae761efd5c7f9eceebfe1146765ae570ea22..fe58dbbe5ee3d16d6fd52060edf40b3749b13f4b 100644 |
| --- a/sdk/lib/collection/list.dart |
| +++ b/sdk/lib/collection/list.dart |
| @@ -28,6 +28,9 @@ typedef ListBase<E> = Object with ListMixin<E>; |
| * mixin to prevent all modifications. |
| */ |
| abstract class ListMixin<E> implements List<E> { |
| + // A list to identify cyclic lists during toString() calls. |
| + static List _toStringList = new List(); |
| + |
| // Iterable interface. |
| Iterator<E> get iterator => new ListIterator<E>(this); |
| @@ -477,5 +480,26 @@ abstract class ListMixin<E> implements List<E> { |
| Iterable<E> get reversed => new ReversedListIterable(this); |
| - String toString() => ToString.iterableToString(this); |
| + String toString() { |
| + for (int i = 0; i < _toStringList.length; i++) { |
| + if (identical(_toStringList[i], this)) { return '[...]'; } |
| + } |
| + |
| + var result = new StringBuffer(); |
| + try { |
| + _toStringList.add(this); |
| + result.write('['); |
| + for (int i = 0; i < length; i++) { |
|
floitsch
2013/07/08 16:12:34
ditto. It would be nice if join wasn't too expensi
zarah
2013/07/08 16:57:46
Use writeAll instead since it is cheaper.
|
| + if (i > 0) { |
| + result.write(', '); |
| + } |
| + result.write(this[i]); |
| + } |
| + result.write(']'); |
| + } finally { |
| + _toStringList.removeLast(); |
|
floitsch
2013/07/08 16:12:34
assert.
zarah
2013/07/08 16:57:46
Done.
|
| + } |
| + |
| + return result.toString(); |
| + } |
| } |