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

Side by Side Diff: runtime/bin/string_stream.dart

Issue 8506005: Merge the two buffer list implementations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
« runtime/bin/buffer_list.dart ('K') | « runtime/bin/socket_stream.dart ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Utility class which can deliver bytes one by one from a number of
6 // buffers added.
7 class _BufferList {
8 _BufferList() : _index = 0, _length = 0, _buffers = new Queue();
9
10 void add(List<int> buffer) {
11 _buffers.addLast(buffer);
12 _length += buffer.length;
13 }
14
15 int peek() {
16 return _buffers.first()[_index];
17 }
18
19 int next() {
20 int value = _buffers.first()[_index++];
21 _length--;
22 if (_index == _buffers.first().length) {
23 _buffers.removeFirst();
24 _index = 0;
25 }
26 return value;
27 }
28
29 int get length() => _length;
30
31 int _length;
32 Queue<List<int>> _buffers;
33 int _index;
34 }
35
36
37 // Interface for decoders decoding binary data into objects of type T. 5 // Interface for decoders decoding binary data into objects of type T.
38 interface _Decoder<T> { 6 interface _Decoder<T> {
39 // Add more binary data to be decoded. The ownership of the buffer 7 // Add more binary data to be decoded. The ownership of the buffer
40 // is transfered to the decoder and the caller most not modify it any more. 8 // is transfered to the decoder and the caller most not modify it any more.
41 int write(List<int> buffer); 9 int write(List<int> buffer);
42 10
43 // Returns whether any decoded data is available. 11 // Returns whether any decoded data is available.
44 bool isEmpty(); 12 bool isEmpty();
45 13
46 // Get the data decoded since the last call to decode. 14 // Get the data decoded since the last call to decode.
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 String _encoding; 313 String _encoding;
346 _Decoder _decoder; 314 _Decoder _decoder;
347 String _buffer; // String can be buffered here if readLine is used. 315 String _buffer; // String can be buffered here if readLine is used.
348 int _bufferLineStart; // Current offset into _buffer if any. 316 int _bufferLineStart; // Current offset into _buffer if any.
349 bool _inputClosed = false; // Is the underlying input stream closed? 317 bool _inputClosed = false; // Is the underlying input stream closed?
350 bool _closed = false; // Is this stream closed. 318 bool _closed = false; // Is this stream closed.
351 bool _eof = false; // Has all data been read from the decoder? 319 bool _eof = false; // Has all data been read from the decoder?
352 var _clientDataHandler; 320 var _clientDataHandler;
353 var _clientCloseHandler; 321 var _clientCloseHandler;
354 } 322 }
OLDNEW
« runtime/bin/buffer_list.dart ('K') | « runtime/bin/socket_stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698