mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-14 00:00:13 +02:00
Fix a couple of bugs
This commit is contained in:
+2
-1
@@ -1,8 +1,9 @@
|
||||
use std::{mem, ptr};
|
||||
use std::rt::heap;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::usize;
|
||||
|
||||
const MAX_ALLOC_SIZE: usize = (1 << 32) - 1;
|
||||
const MAX_ALLOC_SIZE: usize = usize::MAX;
|
||||
|
||||
/// Allocates memory to be used by Bufs or Bytes. Allows allocating memory
|
||||
/// using alternate stratgies than the default Rust heap allocator. Also does
|
||||
|
||||
+8
-5
@@ -307,25 +307,28 @@ impl<'a> Sink for &'a mut Vec<u8> {
|
||||
fn sink<B: Buf>(self, buf: &mut B) -> Result<usize, BufError> {
|
||||
use std::slice;
|
||||
|
||||
self.clear();
|
||||
|
||||
let rem = buf.remaining();
|
||||
let cap = self.capacity();
|
||||
let len = rem - cap;
|
||||
|
||||
// Ensure that the vec is big enough
|
||||
if cap < rem {
|
||||
self.reserve(len);
|
||||
if rem > self.capacity() {
|
||||
self.reserve(rem - cap);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
{
|
||||
let dst = self.as_mut_slice();
|
||||
buf.read_slice(slice::from_raw_parts_mut(dst.as_mut_ptr(), rem));
|
||||
let cnt = buf.read_slice(slice::from_raw_parts_mut(dst.as_mut_ptr(), rem));
|
||||
|
||||
debug_assert!(cnt == rem);
|
||||
}
|
||||
|
||||
self.set_len(rem);
|
||||
}
|
||||
|
||||
Ok(len)
|
||||
Ok(rem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user