|
1 | 1 | use super::{BorrowedBuf, BufReader, BufWriter, Read, Result, Write, DEFAULT_BUF_SIZE};
|
2 | 2 | use crate::alloc::Allocator;
|
3 |
| -use crate::cmp; |
4 | 3 | use crate::collections::VecDeque;
|
5 | 4 | use crate::io::IoSlice;
|
6 | 5 | use crate::mem::MaybeUninit;
|
@@ -255,47 +254,6 @@ impl<I: Write + ?Sized> BufferedWriterSpec for BufWriter<I> {
|
255 | 254 | }
|
256 | 255 | }
|
257 | 256 |
|
258 |
| -impl<A: Allocator> BufferedWriterSpec for Vec<u8, A> { |
259 |
| - fn buffer_size(&self) -> usize { |
260 |
| - cmp::max(DEFAULT_BUF_SIZE, self.capacity() - self.len()) |
261 |
| - } |
262 |
| - |
263 |
| - fn copy_from<R: Read + ?Sized>(&mut self, reader: &mut R) -> Result<u64> { |
264 |
| - let mut bytes = 0; |
265 |
| - |
266 |
| - // avoid allocating before we have determined that there's anything to read |
267 |
| - if self.capacity() == 0 { |
268 |
| - bytes = stack_buffer_copy(&mut reader.take(DEFAULT_BUF_SIZE as u64), self)?; |
269 |
| - if bytes == 0 { |
270 |
| - return Ok(0); |
271 |
| - } |
272 |
| - } |
273 |
| - |
274 |
| - loop { |
275 |
| - self.reserve(DEFAULT_BUF_SIZE); |
276 |
| - let mut buf: BorrowedBuf<'_> = self.spare_capacity_mut().into(); |
277 |
| - match reader.read_buf(buf.unfilled()) { |
278 |
| - Ok(()) => {} |
279 |
| - Err(e) if e.is_interrupted() => continue, |
280 |
| - Err(e) => return Err(e), |
281 |
| - }; |
282 |
| - |
283 |
| - let read = buf.filled().len(); |
284 |
| - if read == 0 { |
285 |
| - break; |
286 |
| - } |
287 |
| - |
288 |
| - // SAFETY: BorrowedBuf guarantees all of its filled bytes are init |
289 |
| - // and the number of read bytes can't exceed the spare capacity since |
290 |
| - // that's what the buffer is borrowing from. |
291 |
| - unsafe { self.set_len(self.len() + read) }; |
292 |
| - bytes += read as u64; |
293 |
| - } |
294 |
| - |
295 |
| - Ok(bytes) |
296 |
| - } |
297 |
| -} |
298 |
| - |
299 | 257 | fn stack_buffer_copy<R: Read + ?Sized, W: Write + ?Sized>(
|
300 | 258 | reader: &mut R,
|
301 | 259 | writer: &mut W,
|
|
0 commit comments