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

Unified Diff: sdk/lib/_internal/compiler/js_lib/convert_patch.dart

Issue 649113005: Make JSON parsing work as a chunked conversion sink. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Fix bug. Created 6 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 | « runtime/lib/double_patch.dart ('k') | sdk/lib/convert/json.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/convert_patch.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/convert_patch.dart b/sdk/lib/_internal/compiler/js_lib/convert_patch.dart
index dd7244d10deba02ebe3b06800a77a3d368136321..2686ca6cdb3eb8f14436833e9244979775e88d02 100644
--- a/sdk/lib/_internal/compiler/js_lib/convert_patch.dart
+++ b/sdk/lib/_internal/compiler/js_lib/convert_patch.dart
@@ -337,3 +337,35 @@ class _JsonMap implements LinkedHashMap {
static _newJavaScriptObject()
=> JS('=Object', 'Object.create(null)');
}
+
+@patch class JsonDecoder {
+ @patch
+ StringConversionSink startChunkedConversion(Sink<Object> sink) {
+ return new _JsonDecoderSink(_reviver, sink);
+ }
+}
+
+/**
+ * Implements the chunked conversion from a JSON string to its corresponding
+ * object.
+ *
+ * The sink only creates one object, but its input can be chunked.
+ */
+// TODO(floitsch): don't accumulate everything before starting to decode.
+class _JsonDecoderSink extends _StringSinkConversionSink {
+ final _Reviver _reviver;
+ final Sink<Object> _sink;
+
+ _JsonDecoderSink(this._reviver, this._sink)
+ : super(new StringBuffer());
+
+ void close() {
+ super.close();
+ StringBuffer buffer = _stringSink;
+ String accumulated = buffer.toString();
+ buffer.clear();
+ Object decoded = _parseJson(accumulated, _reviver);
+ _sink.add(decoded);
+ _sink.close();
+ }
+}
« no previous file with comments | « runtime/lib/double_patch.dart ('k') | sdk/lib/convert/json.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698