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

Side by Side Diff: sdk/lib/convert/string_conversion.dart

Issue 23361015: Make utf8 decoder non-buffered. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/lib/convert/chunked_conversion_utf89_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * This class provides an interface for converters to 8 * This class provides an interface for converters to
9 * efficiently transmit String data. 9 * efficiently transmit String data.
10 * 10 *
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 } 293 }
294 294
295 /** 295 /**
296 * Decodes UTF-8 code units. 296 * Decodes UTF-8 code units.
297 * 297 *
298 * Forwards the decoded strings to the given [StringConversionSink]. 298 * Forwards the decoded strings to the given [StringConversionSink].
299 */ 299 */
300 // TODO(floitsch): make this class public? 300 // TODO(floitsch): make this class public?
301 class _Utf8ConversionSink extends ByteConversionSink { 301 class _Utf8ConversionSink extends ByteConversionSink {
302 static const _MIN_STRING_SIZE = 16;
303 302
304 final _Utf8Decoder _decoder; 303 final _Utf8Decoder _decoder;
305 final StringConversionSink _chunkedSink; 304 final StringConversionSink _chunkedSink;
306 final StringBuffer _buffer; 305 final StringBuffer _buffer;
307 _Utf8ConversionSink(StringConversionSink sink, bool allowMalformed) 306 _Utf8ConversionSink(StringConversionSink sink, bool allowMalformed)
308 : this._(sink, new StringBuffer(), allowMalformed); 307 : this._(sink, new StringBuffer(), allowMalformed);
309 308
310 _Utf8ConversionSink._(this._chunkedSink, StringBuffer stringBuffer, 309 _Utf8ConversionSink._(this._chunkedSink, StringBuffer stringBuffer,
311 bool allowMalformed) 310 bool allowMalformed)
312 : _decoder = new _Utf8Decoder(stringBuffer, allowMalformed), 311 : _decoder = new _Utf8Decoder(stringBuffer, allowMalformed),
313 _buffer = stringBuffer; 312 _buffer = stringBuffer;
314 313
315 void close() { 314 void close() {
316 _decoder.close(); 315 _decoder.close();
317 if (_buffer.isNotEmpty) { 316 if (_buffer.isNotEmpty) {
318 String accumulated = _buffer.toString(); 317 String accumulated = _buffer.toString();
319 _buffer.clear(); 318 _buffer.clear();
320 _chunkedSink.addSlice(accumulated, 0, accumulated.length, true); 319 _chunkedSink.addSlice(accumulated, 0, accumulated.length, true);
321 } else { 320 } else {
322 _chunkedSink.close(); 321 _chunkedSink.close();
323 } 322 }
324 } 323 }
325 324
326 void add(List<int> chunk) { 325 void add(List<int> chunk) {
327 addSlice(chunk, 0, chunk.length, false); 326 addSlice(chunk, 0, chunk.length, false);
328 } 327 }
329 328
330 void addSlice(List<int> chunk, int startIndex, int endIndex, 329 void addSlice(List<int> chunk, int startIndex, int endIndex, bool isLast) {
331 bool isLast) {
332 _decoder.convert(chunk, startIndex, endIndex); 330 _decoder.convert(chunk, startIndex, endIndex);
333 if (_buffer.length > _MIN_STRING_SIZE) { 331 if (_buffer.isNotEmpty) {
334 String accumulated = _buffer.toString(); 332 String accumulated = _buffer.toString();
335 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); 333 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast);
336 _buffer.clear(); 334 _buffer.clear();
337 return; 335 return;
338 } 336 }
339 if (isLast) close(); 337 if (isLast) close();
340 } 338 }
341 } 339 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/convert/chunked_conversion_utf89_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698