Chromium Code Reviews| Index: sdk/lib/_collection_dev/iterable.dart |
| diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart |
| index 6e1e5ecb7c1b79be349de5fd215359d8294a6b0e..29e23289b30837e5160a080d6905ffa444da0ed7 100644 |
| --- a/sdk/lib/_collection_dev/iterable.dart |
| +++ b/sdk/lib/_collection_dev/iterable.dart |
| @@ -702,6 +702,9 @@ abstract class BidirectionalIterator<T> implements Iterator<T> { |
| * The uses of this class will be replaced by mixins. |
| */ |
| class IterableMixinWorkaround { |
| + // A list to identify cyclic collections during toString() calls. |
| + static List _toStringList = new List(); |
| + |
| static bool contains(Iterable iterable, var element) { |
| for (final e in iterable) { |
| if (e == element) return true; |
| @@ -895,6 +898,53 @@ class IterableMixinWorkaround { |
| return buffer.toString(); |
| } |
| + static String toStringIterable(Iterable iterable) { |
| + for (int i = 0; i < _toStringList.length; i++) { |
| + if (identical(_toStringList[i], iterable)) { return '{...}'; } |
| + } |
| + |
| + var result = new StringBuffer(); |
|
floitsch
2013/07/08 16:12:34
Type variable.
zarah
2013/07/08 16:57:46
Done.
|
| + try { |
| + _toStringList.add(iterable); |
| + result.write('{'); |
| + bool first = true; |
| + for (var e in iterable) { |
|
floitsch
2013/07/08 16:12:34
You could see, if iterable.join(", ") doesn't cost
zarah
2013/07/08 16:57:46
Use writeAll instead since it is cheaper.
|
| + if (!first) { |
| + result.write(', '); |
| + } |
| + first = false; |
| + result.write(e); |
| + } |
| + result.write('}'); |
| + } finally { |
|
floitsch
2013/07/08 16:12:34
assert that you are the last.
zarah
2013/07/08 16:57:46
Done.
|
| + _toStringList.removeLast(); |
| + } |
| + return result.toString(); |
| + } |
| + |
| + static String toStringList(List list) { |
| + for (int i = 0; i < _toStringList.length; i++) { |
| + if (identical(_toStringList[i], list)) { return '[...]'; } |
| + } |
| + |
| + var result = new StringBuffer(); |
| + try { |
| + _toStringList.add(list); |
| + result.write('['); |
| + for (int i = 0; i < list.length; i++) { |
|
floitsch
2013/07/08 16:12:34
ditto. If list.join(", ") isn't too expensive it w
zarah
2013/07/08 16:57:46
Use writeAll instead since it is cheaper.
|
| + if (i > 0) { |
| + result.write(', '); |
| + } |
| + result.write(list[i]); |
| + } |
| + result.write(']'); |
| + } finally { |
| + _toStringList.removeLast(); |
| + } |
| + |
| + return result.toString(); |
| + } |
| + |
| static Iterable where(Iterable iterable, bool f(var element)) { |
| return new WhereIterable(iterable, f); |
| } |