Skip to content

Commit a0c76e6

Browse files
committed
Revert "Move toString() to collection classes."
This reverts commit 24836 Review URL: https://codereview.chromium.org//18282008 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@24837 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 8ed47ae commit a0c76e6

File tree

13 files changed

+16
-196
lines changed

13 files changed

+16
-196
lines changed

runtime/lib/array.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class _ObjectArray<E> implements List<E> {
1414
void operator []=(int index, E value) native "ObjectArray_setIndexed";
1515

1616
String toString() {
17-
return IterableMixinWorkaround.toStringIterable(this,'[' , ']');
17+
return ToString.iterableToString(this);
1818
}
1919

2020
int get length native "ObjectArray_getLength";
@@ -457,7 +457,7 @@ class _ImmutableArray<E> implements List<E> {
457457
}
458458

459459
String toString() {
460-
return IterableMixinWorkaround.toStringIterable(this, '[', ']');
460+
return ToString.iterableToString(this);
461461
}
462462

463463
int indexOf(Object element, [int start = 0]) {

runtime/lib/growable_array.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class _GrowableObjectArray<T> implements List<T> {
337337
}
338338

339339
String toString() {
340-
return IterableMixinWorkaround.toStringIterable(this, '[', ']');
340+
return ToString.iterableToString(this);
341341
}
342342

343343
Iterator<T> get iterator {

runtime/lib/typed_data.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ patch class ByteData {
279279
// the collection and list interfaces.
280280

281281
abstract class _TypedListBase {
282-
283282
// Method(s) implementing the Collection interface.
284283
bool contains(element) => IterableMixinWorkaround.contains(this, element);
285284

@@ -506,7 +505,7 @@ abstract class _TypedListBase {
506505
// Method(s) implementing Object interface.
507506

508507
String toString() {
509-
return IterableMixinWorkaround.toStringIterable(this, '[', ']');
508+
return ToString.iterableToString(this);
510509
}
511510

512511

sdk/lib/_collection_dev/iterable.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,6 @@ abstract class BidirectionalIterator<T> implements Iterator<T> {
710710
* The uses of this class will be replaced by mixins.
711711
*/
712712
class IterableMixinWorkaround {
713-
// A list to identify cyclic collections during toString() calls.
714-
static List _toStringList = new List();
715-
716713
static bool contains(Iterable iterable, var element) {
717714
for (final e in iterable) {
718715
if (e == element) return true;
@@ -906,27 +903,6 @@ class IterableMixinWorkaround {
906903
return buffer.toString();
907904
}
908905

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-
930906
static Iterable where(Iterable iterable, bool f(var element)) {
931907
return new WhereIterable(iterable, f);
932908
}

sdk/lib/_internal/lib/js_array.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ part of _interceptors;
1111
* argument added to each member.
1212
*/
1313
class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
14-
1514
const JSArray();
1615

1716
checkMutable(reason) {
18-
if (this is !JSMutableArray) {
17+
if (this is !JSMutableArray) {
1918
throw new UnsupportedError(reason);
2019
}
2120
}
@@ -262,7 +261,7 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable {
262261

263262
bool get isNotEmpty => !isEmpty;
264263

265-
String toString() => IterableMixinWorkaround.toStringIterable(this, '[', ']');
264+
String toString() => ToString.iterableToString(this);
266265

267266
List<E> toList({ bool growable: true }) =>
268267
new List<E>.from(this, growable: growable);

sdk/lib/collection/hash_set.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ part of dart.collection;
66

77
/** Common parts of [HashSet] and [LinkedHashSet] implementations. */
88
abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> {
9-
109
// Set.
1110
bool containsAll(Iterable<Object> other) {
1211
for (Object object in other) {
@@ -54,8 +53,7 @@ abstract class _HashSetBase<E> extends IterableBase<E> implements Set<E> {
5453
retainWhere(retainSet.contains);
5554
}
5655

57-
// TODO(zarah) Remove this, and let it be inherited by IterableBase
58-
String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}');
56+
String toString() => ToString.iterableToString(this);
5957
}
6058

6159
/**

sdk/lib/collection/linked_list.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ part of dart.collection;
1414
class LinkedList<E extends LinkedListEntry<E>>
1515
extends IterableBase<E>
1616
implements _LinkedListLink {
17-
1817
int _modificationCount = 0;
1918
int _length = 0;
2019
_LinkedListLink _next;
@@ -61,8 +60,7 @@ class LinkedList<E extends LinkedListEntry<E>>
6160

6261
Iterator<E> get iterator => new _LinkedListIterator<E>(this);
6362

64-
// TODO(zarah) Remove this, and let it be inherited by IterableMixin
65-
String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}');
63+
String toString() => ToString.iterableToString(this);
6664

6765
int get length => _length;
6866

sdk/lib/collection/list.dart

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ typedef ListBase<E> = Object with ListMixin<E>;
2828
* mixin to prevent all modifications.
2929
*/
3030
abstract class ListMixin<E> implements List<E> {
31-
// A list to identify cyclic lists during toString() calls.
32-
static List _toStringList = new List();
33-
3431
// Iterable interface.
3532
Iterator<E> get iterator => new ListIterator<E>(this);
3633

@@ -480,22 +477,5 @@ abstract class ListMixin<E> implements List<E> {
480477

481478
Iterable<E> get reversed => new ReversedListIterable(this);
482479

483-
String toString() {
484-
for (int i = 0; i < _toStringList.length; i++) {
485-
if (identical(_toStringList[i], this)) { return '[...]'; }
486-
}
487-
488-
var result = new StringBuffer();
489-
try {
490-
_toStringList.add(this);
491-
result.write('[');
492-
result.writeAll(this, ', ');
493-
result.write(']');
494-
} finally {
495-
assert(identical(_toStringList.last, this));
496-
_toStringList.removeLast();
497-
}
498-
499-
return result.toString();
500-
}
480+
String toString() => ToString.iterableToString(this);
501481
}

sdk/lib/collection/maps.dart

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ class Maps {
6060

6161
static bool isNotEmpty(Map map) => map.keys.isNotEmpty;
6262

63-
// A list to identify cyclic maps during toString() calls.
64-
static List _toStringList = new List();
65-
6663
/**
6764
* Returns a string representing the specified map. The returned string
6865
* looks like this: [:'{key0: value0, key1: value1, ... keyN: valueN}':].
@@ -79,33 +76,7 @@ class Maps {
7976
* A typical implementation of a map's [toString] method will
8077
* simply return the results of this method applied to the collection.
8178
*/
82-
static String mapToString(Map m) {
83-
for (int i = 0; i < _toStringList.length; i++) {
84-
if (identical(_toStringList[i], m)) { return '{...}'; }
85-
}
86-
87-
var result = new StringBuffer();
88-
try {
89-
_toStringList.add(m);
90-
result.write('{');
91-
bool first = true;
92-
m.forEach((k, v) {
93-
if(!first) {
94-
result.write(', ');
95-
}
96-
first = false;
97-
result.write(k);
98-
result.write(': ');
99-
result.write(v);
100-
});
101-
result.write('}');
102-
} finally {
103-
assert(identical(_toStringList.last, m));
104-
_toStringList.removeLast();
105-
}
106-
107-
return result.toString();
108-
}
79+
static String mapToString(Map m) => ToString.mapToString(m);
10980

11081
static _id(x) => x;
11182

sdk/lib/collection/queue.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ class DoubleLinkedQueue<E> extends IterableBase<E> implements Queue<E> {
301301
return new _DoubleLinkedQueueIterator<E>(_sentinel);
302302
}
303303

304-
// TODO(zarah) Remove this, and let it be inherited by IterableBase
305-
String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}');
304+
String toString() {
305+
return ToString.iterableToString(this);
306+
}
306307
}
307308

308309
class _DoubleLinkedQueueIterator<E> implements Iterator<E> {
@@ -529,8 +530,9 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> {
529530
}
530531
}
531532

532-
// TODO(zarah) Remove this, and let it be inherited by IterableBase
533-
String toString() => IterableMixinWorkaround.toStringIterable(this, '{', '}');
533+
String toString() {
534+
return ToString.iterableToString(this);
535+
}
534536

535537
// Queue interface.
536538

0 commit comments

Comments
 (0)