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 library http_parser.bytes_builder; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 * Returns `true` if the buffer is not empty. | 79 * Returns `true` if the buffer is not empty. |
80 */ | 80 */ |
81 bool get isNotEmpty; | 81 bool get isNotEmpty; |
82 | 82 |
83 /** | 83 /** |
84 * Clear the contents of the builder. | 84 * Clear the contents of the builder. |
85 */ | 85 */ |
86 void clear(); | 86 void clear(); |
87 } | 87 } |
88 | 88 |
89 | |
90 class _CopyingBytesBuilder implements BytesBuilder { | 89 class _CopyingBytesBuilder implements BytesBuilder { |
91 // Start with 1024 bytes. | 90 // Start with 1024 bytes. |
92 static const int _INIT_SIZE = 1024; | 91 static const int _INIT_SIZE = 1024; |
93 | 92 |
94 int _length = 0; | 93 int _length = 0; |
95 Uint8List _buffer; | 94 Uint8List _buffer; |
96 | 95 |
97 void add(List<int> bytes) { | 96 void add(List<int> bytes) { |
98 int bytesLength = bytes.length; | 97 int bytesLength = bytes.length; |
99 if (bytesLength == 0) return; | 98 if (bytesLength == 0) return; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 --x; | 150 --x; |
152 x |= x >> 1; | 151 x |= x >> 1; |
153 x |= x >> 2; | 152 x |= x >> 2; |
154 x |= x >> 4; | 153 x |= x >> 4; |
155 x |= x >> 8; | 154 x |= x >> 8; |
156 x |= x >> 16; | 155 x |= x >> 16; |
157 return x + 1; | 156 return x + 1; |
158 } | 157 } |
159 } | 158 } |
160 | 159 |
161 | |
162 class _BytesBuilder implements BytesBuilder { | 160 class _BytesBuilder implements BytesBuilder { |
163 int _length = 0; | 161 int _length = 0; |
164 final List _chunks = []; | 162 final List _chunks = []; |
165 | 163 |
166 void add(List<int> bytes) { | 164 void add(List<int> bytes) { |
167 if (bytes is! Uint8List) { | 165 if (bytes is! Uint8List) { |
168 bytes = new Uint8List.fromList(bytes); | 166 bytes = new Uint8List.fromList(bytes); |
169 } | 167 } |
170 _chunks.add(bytes); | 168 _chunks.add(bytes); |
171 _length += bytes.length; | 169 _length += bytes.length; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 203 |
206 bool get isEmpty => _length == 0; | 204 bool get isEmpty => _length == 0; |
207 | 205 |
208 bool get isNotEmpty => _length != 0; | 206 bool get isNotEmpty => _length != 0; |
209 | 207 |
210 void clear() { | 208 void clear() { |
211 _length = 0; | 209 _length = 0; |
212 _chunks.clear(); | 210 _chunks.clear(); |
213 } | 211 } |
214 } | 212 } |
OLD | NEW |