aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaibo Huang <hhb@google.com>2020-07-17 17:53:16 -0700
committerHaibo Huang <hhb@google.com>2020-07-17 17:53:16 -0700
commit293e2aa580e5695f179507500738a4c8fc65ad82 (patch)
tree50b5094b1c55ce2b1bdc01c11e9a741031561006 /src
parent9e908cd8b17b2231e6f526b68c7f2e830422f04d (diff)
downloadbytes-293e2aa580e5695f179507500738a4c8fc65ad82.tar.gz
Upgrade rust/crates/bytes to 0.5.6
Change-Id: Ib95c402dc50956f33008f634e79291a91157cc8d
Diffstat (limited to 'src')
-rw-r--r--src/bytes.rs2
-rw-r--r--src/bytes_mut.rs17
-rw-r--r--src/lib.rs9
3 files changed, 14 insertions, 14 deletions
diff --git a/src/bytes.rs b/src/bytes.rs
index 08bc9b3..79a09f3 100644
--- a/src/bytes.rs
+++ b/src/bytes.rs
@@ -928,7 +928,7 @@ const KIND_VEC: usize = 0b1;
const KIND_MASK: usize = 0b1;
unsafe fn shared_clone(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> Bytes {
- let shared = data.load(Ordering::Acquire);
+ let shared = data.load(Ordering::Relaxed);
shallow_clone_arc(shared as _, ptr, len)
}
diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs
index 4d0585e..a7a8e57 100644
--- a/src/bytes_mut.rs
+++ b/src/bytes_mut.rs
@@ -22,8 +22,12 @@ use crate::{Buf, BufMut, Bytes};
///
/// `BytesMut` represents a unique view into a potentially shared memory region.
/// Given the uniqueness guarantee, owners of `BytesMut` handles are able to
-/// mutate the memory. It is similar to a `Vec<u8>` but with less copies and
-/// allocations.
+/// mutate the memory.
+///
+/// `BytesMut` can be thought of as containing a `buf: Arc<Vec<u8>>`, an offset
+/// into `buf`, a slice length, and a guarantee that no other `BytesMut` for the
+/// same `buf` overlaps with its slice. That guarantee means that a write lock
+/// is not required.
///
/// # Growth
///
@@ -475,6 +479,7 @@ impl BytesMut {
///
/// assert_eq!(&b[..], b"hello world");
/// ```
+ #[inline]
pub unsafe fn set_len(&mut self, len: usize) {
debug_assert!(len <= self.cap, "set_len out of bounds");
self.len = len;
@@ -558,9 +563,8 @@ impl BytesMut {
unsafe {
let (off, prev) = self.get_vec_pos();
- // Only reuse space if we stand to gain at least capacity/2
- // bytes of space back
- if off >= additional && off >= (self.cap / 2) {
+ // Only reuse space if we can satisfy the requested additional space.
+ if self.capacity() - self.len() + off >= additional {
// There's space - reuse it
//
// Just move the pointer back to the start after copying
@@ -1025,6 +1029,7 @@ impl Deref for BytesMut {
}
impl AsMut<[u8]> for BytesMut {
+ #[inline]
fn as_mut(&mut self) -> &mut [u8] {
self.as_slice_mut()
}
@@ -1495,7 +1500,7 @@ static SHARED_VTABLE: Vtable = Vtable {
};
unsafe fn shared_v_clone(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> Bytes {
- let shared = data.load(Ordering::Acquire) as *mut Shared;
+ let shared = data.load(Ordering::Relaxed) as *mut Shared;
increment_shared(shared);
let data = AtomicPtr::new(shared as _);
diff --git a/src/lib.rs b/src/lib.rs
index accbf71..e375c01 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,14 +1,9 @@
-#![deny(
- warnings,
- missing_docs,
- missing_debug_implementations,
- rust_2018_idioms
-)]
+#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![doc(test(
no_crate_inject,
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
-#![doc(html_root_url = "https://docs.rs/bytes/0.5.5")]
+#![doc(html_root_url = "https://docs.rs/bytes/0.5.6")]
#![no_std]
//! Provides abstractions for working with bytes.