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

Side by Side Diff: test/dart_codegen/expect/convert/byte_conversion.dart

Issue 1148283010: Remove dart backend (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(Empty)
1 part of dart.convert;
2 abstract class ByteConversionSink extends ChunkedConversionSink<List<int>> {Byt eConversionSink();
3 factory ByteConversionSink.withCallback(void callback(List<int> accumulated)) = _ByteCallbackSink;
4 factory ByteConversionSink.from(Sink<List<int>> sink) = _ByteAdapterSink;
5 void addSlice(List<int> chunk, int start, int end, bool isLast);
6 }
7 abstract class ByteConversionSinkBase extends ByteConversionSink {void add(List <int> chunk);
8 void close();
9 void addSlice(List<int> chunk, int start, int end, bool isLast) {
10 add(chunk.sublist(start, end));
11 if (isLast) close();
12 }
13 }
14 class _ByteAdapterSink extends ByteConversionSinkBase {final Sink<List<int>> _s ink;
15 _ByteAdapterSink(this._sink);
16 void add(List<int> chunk) => _sink.add(chunk);
17 void close() => _sink.close();
18 }
19 class _ByteCallbackSink extends ByteConversionSinkBase {static const _INITIAL_B UFFER_SIZE = 1024;
20 final _ChunkedConversionCallback<List<int>> _callback;
21 List<int> _buffer = new Uint8List(_INITIAL_BUFFER_SIZE);
22 int _bufferIndex = 0;
23 _ByteCallbackSink(void callback(List<int> accumulated)) : this._callback = call back;
24 void add(Iterable<int> chunk) {
25 int freeCount = _buffer.length - _bufferIndex;
26 if (chunk.length > freeCount) {
27 int oldLength = _buffer.length;
28 int newLength = _roundToPowerOf2(chunk.length + oldLength) * 2;
29 List<int> grown = new Uint8List(newLength);
30 grown.setRange(0, _buffer.length, _buffer);
31 _buffer = grown;
32 }
33 _buffer.setRange(_bufferIndex, _bufferIndex + chunk.length, chunk);
34 _bufferIndex += chunk.length;
35 }
36 static int _roundToPowerOf2(int v) {
37 assert (v > 0); v--;
38 v |= v >> 1;
39 v |= v >> 2;
40 v |= v >> 4;
41 v |= v >> 8;
42 v |= v >> 16;
43 v++;
44 return v;
45 }
46 void close() {
47 _callback(_buffer.sublist(0, _bufferIndex));
48 }
49 }
OLDNEW
« no previous file with comments | « test/dart_codegen/expect/convert/ascii.dart ('k') | test/dart_codegen/expect/convert/chunked_conversion.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698