Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Builds a list of bytes, allowing bytes and lists of bytes to be added at the | 8 * Builds a list of bytes, allowing bytes and lists of bytes to be added at the |
| 9 * end. | 9 * end. |
| 10 * | 10 * |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Returns the contents of `this` and clears `this`. | 61 * Returns the contents of `this` and clears `this`. |
| 62 * | 62 * |
| 63 * The list returned is a view of the the internal buffer, limited to the | 63 * The list returned is a view of the the internal buffer, limited to the |
| 64 * [length]. | 64 * [length]. |
| 65 */ | 65 */ |
| 66 List<int> takeBytes() { | 66 List<int> takeBytes() { |
| 67 if (_buffer == null) return new Uint8List(0); | 67 if (_buffer == null) return new Uint8List(0); |
| 68 var buffer = _buffer; | 68 var buffer = _buffer; |
| 69 int length = _length; | |
| 69 clear(); | 70 clear(); |
| 70 return new Uint8List.view(buffer.buffer, 0, _length); | 71 return new Uint8List.view(buffer.buffer, 0, length); |
|
Bill Hesse
2013/07/12 10:23:25
Very funny bug!
| |
| 71 } | 72 } |
| 72 | 73 |
| 73 /** | 74 /** |
| 74 * Returns a copy of the current contents of the builder. | 75 * Returns a copy of the current contents of the builder. |
| 75 * | 76 * |
| 76 * Leaves the contents of the builder intact. | 77 * Leaves the contents of the builder intact. |
| 77 */ | 78 */ |
| 78 List<int> toBytes() { | 79 List<int> toBytes() { |
| 79 if (_buffer == null) return new Uint8List(0); | 80 if (_buffer == null) return new Uint8List(0); |
| 80 return new Uint8List.fromList( | 81 return new Uint8List.fromList( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 107 int _pow2roundup(int x) { | 108 int _pow2roundup(int x) { |
| 108 --x; | 109 --x; |
| 109 x |= x >> 1; | 110 x |= x >> 1; |
| 110 x |= x >> 2; | 111 x |= x >> 2; |
| 111 x |= x >> 4; | 112 x |= x >> 4; |
| 112 x |= x >> 8; | 113 x |= x >> 8; |
| 113 x |= x >> 16; | 114 x |= x >> 16; |
| 114 return x + 1; | 115 return x + 1; |
| 115 } | 116 } |
| 116 } | 117 } |
| OLD | NEW |