Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: pkg/json/lib/json.dart

Issue 25548010: Make JSON encoder take extra function argument to use instead of toJson calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename convert function to "toEncodable". Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/convert/json.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/json/lib/json.dart
diff --git a/pkg/json/lib/json.dart b/pkg/json/lib/json.dart
index 58b6c796d6135abbc02ed18dda51d1c6ed7a2e98..f7063382c6ddb05aa8a4ec6cfa7da1c985a8d960 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.
/**
@@ -665,10 +667,10 @@ class JsonParser {
class _JsonStringifier {
- StringSink sink;
- List<Object> seen; // TODO: that should be identity set.
+ final StringSink sink;
+ final 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;
« no previous file with comments | « no previous file | sdk/lib/convert/json.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698