Chromium Code Reviews| Index: sdk/lib/collection/maps.dart |
| diff --git a/sdk/lib/collection/maps.dart b/sdk/lib/collection/maps.dart |
| index 303008cc6950a815089473c7b0f4e181b89cda13..2cb86de55441e09d18be503111276a5c2b0d031f 100644 |
| --- a/sdk/lib/collection/maps.dart |
| +++ b/sdk/lib/collection/maps.dart |
| @@ -59,7 +59,10 @@ class Maps { |
| static bool isEmpty(Map map) => map.keys.isEmpty; |
| static bool isNotEmpty(Map map) => map.keys.isNotEmpty; |
| - |
| + |
|
Lasse Reichstein Nielsen
2013/07/09 06:15:44
Extra spaces added.
zarah
2013/07/09 08:20:54
Done.
|
| + // A list to identify cyclic maps during toString() calls. |
| + static List _toStringList = new List(); |
| + |
| /** |
| * Returns a string representing the specified map. The returned string |
| * looks like this: [:'{key0: value0, key1: value1, ... keyN: valueN}':]. |
| @@ -76,7 +79,33 @@ class Maps { |
| * A typical implementation of a map's [toString] method will |
| * simply return the results of this method applied to the collection. |
| */ |
| - static String mapToString(Map m) => ToString.mapToString(m); |
| + static String mapToString(Map m) { |
| + for (int i = 0; i < _toStringList.length; i++) { |
| + if (identical(_toStringList[i], m)) { return '{...}'; } |
| + } |
| + |
| + var result = new StringBuffer(); |
| + try { |
| + _toStringList.add(m); |
| + result.write('{'); |
| + bool first = true; |
| + m.forEach((k, v) { |
| + if(!first) { |
| + result.write(', '); |
| + } |
| + first = false; |
|
Lasse Reichstein Nielsen
2013/07/09 06:15:44
Consider moving this assignment into the condition
zarah
2013/07/09 08:20:54
Not done, as discussed.
|
| + result.write(k); |
| + result.write(': '); |
| + result.write(v); |
| + }); |
| + result.write('}'); |
| + } finally { |
| + assert(identical(_toStringList.last, m)); |
| + _toStringList.removeLast(); |
| + } |
| + |
| + return result.toString(); |
| + } |
| static _id(x) => x; |