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

Unified Diff: sdk/lib/collection/list.dart

Issue 26481002: Change the toString method of IterableBase/IterableMixin to show some elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/linked_list.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/collection/list.dart
diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart
index eed6b32cefb5966d4803b52e881d8b85e1401697..f31c6e91a6a87f5514dd60768ca31dcfc3804774 100644
--- a/sdk/lib/collection/list.dart
+++ b/sdk/lib/collection/list.dart
@@ -4,6 +4,9 @@
part of dart.collection;
+/** A reusable set used to identify cyclic lists during toString() calls. */
+Set _toStringVisiting = new HashSet.identity();
+
/**
* Abstract implementation of a list.
*
@@ -22,8 +25,6 @@ typedef ListBase<E> = Object with ListMixin<E>;
* `length=` and `operator[]=`
*/
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);
@@ -487,19 +488,18 @@ abstract class ListMixin<E> implements List<E> {
Iterable<E> get reversed => new ReversedListIterable(this);
String toString() {
- for (int i = 0; i < _toStringList.length; i++) {
- if (identical(_toStringList[i], this)) { return '[...]'; }
+ if (_toStringVisiting.contains(this)) {
+ return '[...]';
}
var result = new StringBuffer();
try {
- _toStringList.add(this);
+ _toStringVisiting.add(this);
result.write('[');
result.writeAll(this, ', ');
result.write(']');
} finally {
- assert(identical(_toStringList.last, this));
- _toStringList.removeLast();
+ _toStringVisiting.remove(this);
}
return result.toString();
« no previous file with comments | « sdk/lib/collection/linked_list.dart ('k') | sdk/lib/collection/queue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698