Age | Commit message (Collapse) | Author | Files | Lines |
|
We don't need the original capacity if the shared data is unique, so
let's not calculate it until after that check.
|
|
We're always subtracting here, and we already have a usize, so `sub`
seems like a more appropriate usage to me.
|
|
These seem to have been commented by accident in #298, and are still
passing.
|
|
Instead of re-declaring `vec`, we can just use a mut parameter.
|
|
|
|
|
|
|
|
|
|
Back in #362, an assertion was added to ensure that the alignment of
bytes::Shared is even so we can use the least significant bit as a flag.
bytes_mut::Shared uses the same technique but has no such assertion so
I've added one here.
|
|
I was a little confused about these calls using `Self::` instead of
`self.` here. Is there a reason to use the former instead of the latter?
|
|
This reworks `UninitSlice::as_uninit_slice_mut()` using equivalent
simpler logic.
|
|
Fixed a few broken links and converted a lot of them from the
html-link to intra-doc links.
|
|
Co-authored-by: Daniel Bauman <danielbauman@Daniels-MacBook-Pro.local>
|
|
|
|
|
|
|
|
tokio::io::ReadBuf uses names `new` and `uninit` for its constructors.
For consistency with that, rename recently introduced UninitSlice
constructors to match those names.
|
|
|
|
Introduce UninitSlice::from_slice and UninitSlice::from_uninit_slice
methods which safely create Uninit slice from provided slice of maybe
uninitialised or initialised memory.
In addition, add `From<&mut [T]>` implementations (for `T=u8` and
`T=MaybeUninit<u8>`) which do conversion from slice to UninitSlice.
Closes: #552
|
|
This function can be hot in applications that do a lot of encoding. Ideally would do the same for `<BytesMut as BufMut>::put_slice` and `<BytesMut as BufMut::put_u8`.
|
|
When we freeze a BytesMut, we turn it into a Vec, and then convert that
to a Bytes. Currently, this happen using Vec::into_boxed_slice, which
reallocates to a slice of the same length as the Vev if the length and
the capacity are not equal. This can pose a performance problem if the
Vec is large or if this happens many times in a loop.
Instead, let's compare the length and capacity, and if they're the same,
continue to handle this using into_boxed_slice. Otherwise, since we
have a type of vtable which can handle a separate capacity, the shared
vtable, let's turn our Vec into that kind of Bytes. While this does not
avoid allocation altogether, it performs a fixed size allocation and
avoids any need to memcpy.
|
|
|
|
Co-authored-by: Nicolae Mihalache <nicolae.mihalache@spaceapplications.com>
|
|
|
|
Fixes #549
|
|
|
|
|
|
|
|
Fixes calls to `reserve` when the underlying shared buffer was already
big enough to fit the requested capacity. Previously a new even larger
buffer was created anyways. This could eventually lead to an OOM
condition.
|
|
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
|
|
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
|
|
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
|
|
|
|
|
|
|
|
This adds an unsafe method to convert a `&mut UninitSlice` into a
`&mut [MaybeUninit<u8>]`. This method is unsafe because some of the
bytes in the slice may be initialized, and the caller should not
overwrite them with uninitialized bytes.
This came about when auditing [tokio-util's udp frame], where they want
to pass the unitialized portion of a `BytesMut` to [ReadBuf::uninit].
They need to do this unsafe pointer casting in a few places, which
complicates audits. This method lets us document the safety invariants
the caller needs to maintain when doing this conversion.
[tokio-util's udp frame]: https://github.com/tokio-rs/tokio/blob/master/tokio-util/src/udp/frame.rs#L87
[ReadBuf::uninit]: https://docs.rs/tokio/latest/tokio/io/struct.ReadBuf.html#method.uninit
|
|
|
|
This reverts commit 89061c323861c4e9555881fef940836f1cd132cc.
Why am I even able to push to master?
|
|
|
|
|
|
|
|
|
|
Previously, this code produced a &mut[u8] and a Box<[u8]> to the shared
allocation upon cloning it. If the underlying allocation were actually
shared, such as through a &[u8] from the Deref impl, creating either of
these types incorrectly asserted uniqueness of the allocation.
This fixes the example in #522, but Miri still does not pass on this
test suite with -Zmiri-tag-raw-pointers because Miri does not currently
understand int to pointer casts.
|
|
|
|
I find this diagram very helpful, but a little hard to distinguish
between the boxes and the lines that connect them. This commit redraws
the boxes with line drawing characters so that the boxes appear a
little more solid, and stand out from the other lines.
|
|
* Optimize `BytesMut::reserve`: Reuse vec if possible
If the `BytesMut` holds a unqiue reference to `KIND_ARC` while the
capacity of the `Vec` is not big enough , reuse the existing `Vec`
instead of allocating a new one.
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
|
|
|
|
|
|
|
|
|