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

Unified Diff: runtime/lib/convert_patch.dart

Issue 689043002: Make JSON.fuse(UTF8) be more efficient by not creating intermediate string. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 1 month 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/_internal/compiler/js_lib/convert_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/convert_patch.dart
diff --git a/runtime/lib/convert_patch.dart b/runtime/lib/convert_patch.dart
index eea0fa5f2a4b32d59c354c676d67bfa099371250..d8ca287abbed49d179f4c6d8eba3caff27121dee 100644
--- a/runtime/lib/convert_patch.dart
+++ b/runtime/lib/convert_patch.dart
@@ -21,6 +21,36 @@ patch _parseJson(String json, reviver(var key, var value)) {
return listener.result;
}
+patch class Utf8Decoder {
+ /* patch */
+ Converter<List<int>, dynamic> fuse(Converter<String, dynamic> next) {
+ if (next is JsonDecoder) {
+ return new _JsonUtf8Decoder(next._reviver, this._allowMalformed);
+ }
+ // TODO(lrn): Recognize a fused decoder where the next step is JsonDecoder.
+ return super.fuse(next);
+ }
+}
+
+class _JsonUtf8Decoder extends Converter<List<int>, Object> {
+ final _Reviver _reviver;
+ final bool _allowMalformed;
+
+ _JsonUtf8Decoder(this._reviver, this._allowMalformed);
+
+ dynamic convert(List<int> input) {
+ var parser = _JsonUtf8DecoderSink._createParser(_reviver, _allowMalformed);
+ parser.chunk = input;
+ parser.chunkEnd = input.length;
+ parser.parse(0);
+ return parser.result;
+ }
+
+ ByteConversionSink startChunkedConversion(Sink<Object> sink) {
+ return new _JsonUtf8DecoderSink(_reviver, sink, _allowMalformed);
+ }
+}
+
//// Implementation ///////////////////////////////////////////////////////////
// Simple API for JSON parsing.
@@ -760,6 +790,9 @@ abstract class _ChunkedJsonParser {
int state = this.state;
while (position < length) {
int char = getChar(position);
+ if (char == null) {
+ print("[[[$chunk]]] - $position - ${chunk.runtimeType}");
+ }
switch (char) {
case SPACE:
case CARRIAGE_RETURN:
@@ -847,6 +880,7 @@ abstract class _ChunkedJsonParser {
default:
if ((state & ALLOW_VALUE_MASK) != 0) fail(position);
state |= VALUE_READ_BITS;
+ if (char == null) print("$chunk - $position");
position = parseNumber(char, position);
break;
}
@@ -1240,7 +1274,7 @@ abstract class _ChunkedJsonParser {
listener.handleNumber(sign * intValue);
return position;
}
- // Double values at or above this value (2**53) may have lost precission.
+ // Double values at or above this value (2 ** 53) may have lost precission.
// Only trust results that are below this value.
const double maxExactDouble = 9007199254740992.0;
if (doubleValue < maxExactDouble) {
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/convert_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698