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

Side by Side Diff: runtime/bin/buffer_list.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
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/socket_stream.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /*
Mads Ager (google) 2011/11/09 09:46:15 These are nice comments. Maybe use the dart doc fo
Søren Gjesse 2011/11/09 09:58:38 Done.
6 * Utility class that holds a number of byte buffers and can deliver
7 * the bytes either one by one or in chunks.
8 */
9 class _BufferList {
10 _BufferList() {
11 clear();
12 }
13
14 /*
15 * Adds a new buffer to the list possibly with an offset of the
16 * first byte of interest. The offset can only be specified if the
17 * buffer list is empty.
18 */
19 void add(List<int> buffer, [int offset = 0]) {
20 assert(offset == 0 || _buffers.isEmpty());
21 _buffers.addLast(buffer);
22 _length += buffer.length;
23 if (offset != 0) _index = offset;
24 }
25
26 /*
27 * Returns the first buffer from the list. This returns the whole
28 * buffer and does not remove the buffer from the list. Use
29 * [index()] to determine the index of the first byte in the buffer.
Mads Ager (google) 2011/11/09 09:46:15 remove the () from [index()] or use code comments
Søren Gjesse 2011/11/09 09:58:38 Removed () (it is a getter)
30 */
31 List<int> get first() => _buffers.first();
32
33 /* Returns the current index of the next byte. This will always be
34 * an index into the first buffer as when the index is advanced past
35 * the end of a buffer it is removed from the list.
36 */
37 int get index() => _index;
38
39 /*
40 * Peek at the next available byte.
41 */
42 int peek() {
Mads Ager (google) 2011/11/09 09:46:15 use '=>' syntax?
Søren Gjesse 2011/11/09 09:58:38 Done.
43 return _buffers.first()[_index];
44 }
45
46 /*
47 * Returns the next available byte removing it from the buffers.
48 */
49 int next() {
50 int value = _buffers.first()[_index++];
51 _length--;
52 if (_index == _buffers.first().length) {
53 _buffers.removeFirst();
54 _index = 0;
55 }
56 return value;
57 }
58
59 /*
60 * Removed a number of bytes from the buffer list. Currently the
Mads Ager (google) 2011/11/09 09:46:15 Removed -> Remove
Søren Gjesse 2011/11/09 09:58:38 Done.
61 * number of bytes to remove must be confined to the first buffer.
62 */
63 void removeBytes(int count) {
64 int firstRemaining = first.length - _index;
65 assert(count <= firstRemaining);
66 if (count == firstRemaining) {
67 _buffers.removeFirst();
68 _index = 0;
69 } else {
70 _index += count;
71 }
72 _length -= count;
73 }
74
75
76 /*
77 * Returns the total number of bytes remaining in the buffers.
78 */
79 int get length() => _length;
80
81 /*
82 * Returns whether the buffer list is empty that is has no bytes
83 * available.
84 */
85 bool isEmpty() => _buffers.isEmpty();
86
87 /*
88 * Clears the content of the buffer list.
89 */
90 void clear() {
91 _index = 0;
92 _length = 0;
93 _buffers = new Queue();
94 }
95
96 int _length; // Total number of bytes remaining in the buffers.
97 Queue<List<int>> _buffers; // List of data buffers.
98 int _index; // Index of the next byte in the first buffer.
99 }
OLDNEW
« no previous file with comments | « runtime/bin/bin.gypi ('k') | runtime/bin/socket_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698