| 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 // This is a copy of "dart:io"'s BytesBuilder implementation, from | 5 // This is a copy of "dart:io"'s BytesBuilder implementation, from |
| 6 // sdk/lib/io/bytes_builder.dart. It's copied here to make it available to | 6 // sdk/lib/io/bytes_builder.dart. It's copied here to make it available to |
| 7 // non-"dart:io" applications (issue 18348). | 7 // non-"dart:io" applications (issue 18348). |
| 8 // | 8 // |
| 9 // Because it's copied directly, there are no modifications from the original. | 9 // Because it's copied directly, there are no modifications from the original. |
| 10 library http_parser.bytes_builder; | 10 // |
| 11 // This is up-to-date as of sdk revision |
| 12 // 86227840d75d974feb238f8b3c59c038b99c05cf. |
| 13 library http_parser.copy.bytes_builder; |
| 11 | 14 |
| 12 import 'dart:math'; | 15 import 'dart:math'; |
| 13 import 'dart:typed_data'; | 16 import 'dart:typed_data'; |
| 14 | 17 |
| 15 /** | 18 /** |
| 16 * Builds a list of bytes, allowing bytes and lists of bytes to be added at the | 19 * Builds a list of bytes, allowing bytes and lists of bytes to be added at the |
| 17 * end. | 20 * end. |
| 18 * | 21 * |
| 19 * Used to efficiently collect bytes and lists of bytes. | 22 * Used to efficiently collect bytes and lists of bytes. |
| 20 */ | 23 */ |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 * Returns `true` if the buffer is not empty. | 82 * Returns `true` if the buffer is not empty. |
| 80 */ | 83 */ |
| 81 bool get isNotEmpty; | 84 bool get isNotEmpty; |
| 82 | 85 |
| 83 /** | 86 /** |
| 84 * Clear the contents of the builder. | 87 * Clear the contents of the builder. |
| 85 */ | 88 */ |
| 86 void clear(); | 89 void clear(); |
| 87 } | 90 } |
| 88 | 91 |
| 92 |
| 89 class _CopyingBytesBuilder implements BytesBuilder { | 93 class _CopyingBytesBuilder implements BytesBuilder { |
| 90 // Start with 1024 bytes. | 94 // Start with 1024 bytes. |
| 91 static const int _INIT_SIZE = 1024; | 95 static const int _INIT_SIZE = 1024; |
| 92 | 96 |
| 93 int _length = 0; | 97 int _length = 0; |
| 94 Uint8List _buffer; | 98 Uint8List _buffer; |
| 95 | 99 |
| 96 void add(List<int> bytes) { | 100 void add(List<int> bytes) { |
| 97 int bytesLength = bytes.length; | 101 int bytesLength = bytes.length; |
| 98 if (bytesLength == 0) return; | 102 if (bytesLength == 0) return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 --x; | 154 --x; |
| 151 x |= x >> 1; | 155 x |= x >> 1; |
| 152 x |= x >> 2; | 156 x |= x >> 2; |
| 153 x |= x >> 4; | 157 x |= x >> 4; |
| 154 x |= x >> 8; | 158 x |= x >> 8; |
| 155 x |= x >> 16; | 159 x |= x >> 16; |
| 156 return x + 1; | 160 return x + 1; |
| 157 } | 161 } |
| 158 } | 162 } |
| 159 | 163 |
| 164 |
| 160 class _BytesBuilder implements BytesBuilder { | 165 class _BytesBuilder implements BytesBuilder { |
| 161 int _length = 0; | 166 int _length = 0; |
| 162 final List _chunks = []; | 167 final List _chunks = []; |
| 163 | 168 |
| 164 void add(List<int> bytes) { | 169 void add(List<int> bytes) { |
| 165 if (bytes is! Uint8List) { | 170 if (bytes is! Uint8List) { |
| 166 bytes = new Uint8List.fromList(bytes); | 171 bytes = new Uint8List.fromList(bytes); |
| 167 } | 172 } |
| 168 _chunks.add(bytes); | 173 _chunks.add(bytes); |
| 169 _length += bytes.length; | 174 _length += bytes.length; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 208 |
| 204 bool get isEmpty => _length == 0; | 209 bool get isEmpty => _length == 0; |
| 205 | 210 |
| 206 bool get isNotEmpty => _length != 0; | 211 bool get isNotEmpty => _length != 0; |
| 207 | 212 |
| 208 void clear() { | 213 void clear() { |
| 209 _length = 0; | 214 _length = 0; |
| 210 _chunks.clear(); | 215 _chunks.clear(); |
| 211 } | 216 } |
| 212 } | 217 } |
| OLD | NEW |