@@ -710,6 +710,9 @@ abstract class BidirectionalIterator<T> implements Iterator<T> {
710710 * The uses of this class will be replaced by mixins.
711711 */
712712class IterableMixinWorkaround {
713+ // A list to identify cyclic collections during toString() calls.
714+ static List _toStringList = new List ();
715+
713716 static bool contains (Iterable iterable, var element) {
714717 for (final e in iterable) {
715718 if (e == element) return true ;
@@ -903,6 +906,27 @@ class IterableMixinWorkaround {
903906 return buffer.toString ();
904907 }
905908
909+ static String toStringIterable (Iterable iterable, String leftDelimiter,
910+ String rightDelimiter) {
911+ for (int i = 0 ; i < _toStringList.length; i++ ) {
912+ if (identical (_toStringList[i], iterable)) {
913+ return '$leftDelimiter ...$rightDelimiter ' ;
914+ }
915+ }
916+
917+ StringBuffer result = new StringBuffer ();
918+ try {
919+ _toStringList.add (iterable);
920+ result.write (leftDelimiter);
921+ result.writeAll (iterable, ', ' );
922+ result.write (rightDelimiter);
923+ } finally {
924+ assert (identical (_toStringList.last, iterable));
925+ _toStringList.removeLast ();
926+ }
927+ return result.toString ();
928+ }
929+
906930 static Iterable where (Iterable iterable, bool f (var element)) {
907931 return new WhereIterable (iterable, f);
908932 }
0 commit comments