Chromium Code Reviews| Index: runtime/bin/buffer_list.dart |
| diff --git a/runtime/bin/buffer_list.dart b/runtime/bin/buffer_list.dart |
| index 540557ab00990e55d5dc49d17882d04328bc2114..bce8ab765a0d461a11a3800f5c6442fe051140c1 100644 |
| --- a/runtime/bin/buffer_list.dart |
| +++ b/runtime/bin/buffer_list.dart |
| @@ -54,6 +54,56 @@ class _BufferList { |
| return value; |
| } |
| + /* |
|
Mads Ager (google)
2011/12/06 14:05:02
Do you want to use DartDoc style here: '/**'?
Hal
Søren Gjesse
2011/12/07 07:58:29
I am not realy sure. This is an internal class. Ma
|
| + * Read [count] bytes from the buffer list. If the number of bytes |
| + * requested is not available null will be returned. |
| + */ |
| + List<int> readBytes(int count) { |
| + List<int> result; |
| + if (_length == 0 || _length < count) return null; |
| + if (_index == 0 && _buffers.first().length == count) { |
| + result = _buffers.first(); |
| + _buffers.removeFirst(); |
| + _index = 0; |
| + _length -= count; |
| + return result; |
| + } else { |
| + int firstRemaining = _buffers.first().length - _index; |
| + if (firstRemaining >= count) { |
| + result = _buffers.first().getRange(_index, count); |
| + _index += count; |
| + _length -= count; |
| + return result; |
| + } else { |
| + result = new List<int>(count); |
| + int remaining = count; |
| + while (remaining > 0) { |
| + int bytesInFirst = _buffers.first().length - _index; |
| + if (bytesInFirst <= remaining) { |
| + result.setRange(count - remaining, |
| + bytesInFirst, |
| + _buffers.first(), |
| + _index); |
| + _buffers.removeFirst(); |
| + _index = 0; |
| + _length -= bytesInFirst; |
| + remaining -= bytesInFirst; |
| + } else { |
| + result.setRange(count - remaining, |
| + remaining, |
| + _buffers.first(), |
| + _index); |
| + _index = remaining; |
| + _length -= remaining; |
| + remaining = 0; |
| + assert(_index < _buffers.first().length); |
| + } |
| + } |
| + return result; |
| + } |
| + } |
| + } |
| + |
| /** |
| * Remove a number of bytes from the buffer list. Currently the |
| * number of bytes to remove must be confined to the first buffer. |