Chromium Code Reviews| Index: pkg/json/lib/json.dart |
| diff --git a/pkg/json/lib/json.dart b/pkg/json/lib/json.dart |
| index 58b6c796d6135abbc02ed18dda51d1c6ed7a2e98..fb36f31084242802bcd8bdc0a8e352c2376e2acb 100644 |
| --- a/pkg/json/lib/json.dart |
| +++ b/pkg/json/lib/json.dart |
| @@ -8,6 +8,8 @@ |
| library json; |
| +import "dart:collection" show HashSet; |
| + |
| // JSON parsing and serialization. |
| /** |
| @@ -666,9 +668,9 @@ class JsonParser { |
| class _JsonStringifier { |
| StringSink sink; |
|
kevmoo-old
2013/10/04 16:31:08
final * 2
Lasse Reichstein Nielsen
2013/10/07 12:46:59
Done.
|
| - List<Object> seen; // TODO: that should be identity set. |
| + Set<Object> seen; |
| - _JsonStringifier(this.sink) : seen = []; |
| + _JsonStringifier(this.sink) : seen = new HashSet.identity(); |
| static String stringify(final object) { |
| StringBuffer output = new StringBuffer(); |
| @@ -735,11 +737,8 @@ class _JsonStringifier { |
| } |
| void checkCycle(final object) { |
| - // TODO: use Iterables. |
| - for (int i = 0; i < seen.length; i++) { |
| - if (identical(seen[i], object)) { |
| - throw new JsonCyclicError(object); |
| - } |
| + if (seen.contains(object)) { |
| + throw new JsonCyclicError(object); |
| } |
| seen.add(object); |
| } |
| @@ -755,7 +754,7 @@ class _JsonStringifier { |
| if (!stringifyJsonValue(customJson)) { |
| throw new JsonUnsupportedObjectError(object); |
| } |
| - seen.removeLast(); |
| + seen.remove(object); |
| } catch (e) { |
| throw new JsonUnsupportedObjectError(object, cause: e); |
| } |
| @@ -800,7 +799,7 @@ class _JsonStringifier { |
| } |
| } |
| sink.write(']'); |
| - seen.removeLast(); |
| + seen.remove(object); |
| return true; |
| } else if (object is Map) { |
| checkCycle(object); |
| @@ -819,7 +818,7 @@ class _JsonStringifier { |
| first = false; |
| }); |
| sink.write('}'); |
| - seen.removeLast(); |
| + seen.remove(object); |
| return true; |
| } else { |
| return false; |