aboutsummaryrefslogtreecommitdiff
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-02-06Calculate original capacity only if necessary (#666)Gravatar Brad Dunbar 1-6/+3
We don't need the original capacity if the shared data is unique, so let's not calculate it until after that check.
2024-02-06Use sub instead of offset (#668)Gravatar Brad Dunbar 1-2/+2
We're always subtracting here, and we already have a usize, so `sub` seems like a more appropriate usage to me.
2024-02-06Restore commented tests (#665)Gravatar Brad Dunbar 1-38/+41
These seem to have been commented by accident in #298, and are still passing.
2024-01-31refactor: make parameter mut in From<Vec> (#667)Gravatar Brad Dunbar 1-2/+1
Instead of re-declaring `vec`, we can just use a mut parameter.
2024-01-28Remove unreachable else branch (#661)Gravatar Brad Dunbar 1-3/+1
2024-01-28Remove an unnecessary else branch (#662)Gravatar Brad Dunbar 1-2/+2
2024-01-28Remove unnecessary namespace qualifier (#660)Gravatar Brad Dunbar 2-3/+3
2024-01-19add `Bytes::is_unique` (#643)Gravatar Cyborus04 2-0/+51
2024-01-19BytesMut: Assert alignment of Shared (#652)Gravatar Brad Dunbar 1-0/+6
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.
2023-12-28Use `self.` instead of `Self::` (#642)Gravatar Brad Dunbar 1-6/+6
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?
2023-12-28Simplify UninitSlice::as_uninit_slice_mut() logic (#644)Gravatar Luca Bruno 1-1/+1
This reworks `UninitSlice::as_uninit_slice_mut()` using equivalent simpler logic.
2023-11-16docs: fix broken links (#639)Gravatar Gabriel Goller 9-25/+9
Fixed a few broken links and converted a lot of them from the html-link to intra-doc links.
2023-10-19docs: typo fix (#637)Gravatar DanielB 1-2/+2
Co-authored-by: Daniel Bauman <danielbauman@Daniels-MacBook-Pro.local>
2023-10-02Various cleanup (#635)Gravatar Alice Ryhl 7-136/+350
2023-09-25docs: fix some spelling mistakes (#633)Gravatar mxsm 2-2/+2
2023-09-11Move comment to correct constant (#629)Gravatar Lucas Kent 1-1/+1
2023-06-20Rename UninitSlice constructors for consistency with ReadBuf (#599)Gravatar Michal Nazarewicz 2-24/+24
tokio::io::ReadBuf uses names `new` and `uninit` for its constructors. For consistency with that, rename recently introduced UninitSlice constructors to match those names.
2023-02-10Implement BufMut for `&mut [MaybeUninit<u8>]` (#597)Gravatar Michal Nazarewicz 1-0/+35
2023-02-09Add a safe way to create UninitSlice from slices (#598)Gravatar Michal Nazarewicz 2-7/+51
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
2023-02-04Mark BytesMut::extend_from_slice as inline (#595)Gravatar Paa Kojo Samanpa 1-0/+1
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`.
2023-01-31Avoid large reallocations when freezing BytesMut (#592)Gravatar brian m. carlson 1-2/+30
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.
2023-01-31Document which functions require `std` (#591)Gravatar 0xc0001a2040 3-0/+4
2022-12-20Fix duplicate "the the" typos (#585)Gravatar Nicolae Mihalache 1-2/+2
Co-authored-by: Nicolae Mihalache <nicolae.mihalache@spaceapplications.com>
2022-11-25make IntoIter constructor public (#581)Gravatar Matthijs van Otterdijk 1-3/+1
2022-11-14Implement native-endian get and put functions for Buf and BufMut (#576)Gravatar Sean Lynch 2-0/+664
Fixes #549
2022-10-04Rename and expose `BytesMut::spare_capacity_mut` (#572)Gravatar Yotam Ofek 2-8/+41
2022-08-24docs: Bytes::new etc should return Self not Bytes (#568)Gravatar Adam Chalmers 1-8/+8
2022-08-12Don't have important data in unused capacity when calling reserve (#563)Gravatar Alice Ryhl 1-0/+9
2022-07-30Fix reserve over allocating underlying buffer (#560)Gravatar Matt Schulte 1-1/+4
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.
2022-07-19Fix amortized asymptotics of `BytesMut` (#555)Gravatar Jiahao XU 2-15/+67
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: Frank Steffahn <frank.steffahn@stu.uni-kiel.de>
2022-07-13Add conversion from Bytes to Vec<u8> (#547)Gravatar Jiahao XU 2-0/+112
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> Co-authored-by: Alice Ryhl <aliceryhl@google.com>
2022-07-13Fix: `From<BytesMut> fo Vec<u8>` implementation (#554)Gravatar Jiahao XU 1-5/+6
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2022-07-10Add conversion from BytesMut to Vec<u8> (#543)Gravatar Jiahao XU 1-0/+37
2022-07-09miri: don't use int2ptr casts for invalid pointers (#553)Gravatar Alice Ryhl 1-9/+21
2022-06-11Fix chain remaining_mut(), allowing to chain growing buffer (#488)Gravatar Zettroke 2-2/+5
2022-05-10Add `UninitSlice::as_uninit_slice_mut()` (#548)Gravatar Erick Tryzelaar 1-0/+26
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
2022-04-29Only avoid pointer casts when using miri (#545)Gravatar Alice Ryhl 1-2/+19
2022-04-29Revert accidental push directly to masterGravatar Alice Ryhl 1-13/+2
This reverts commit 89061c323861c4e9555881fef940836f1cd132cc. Why am I even able to push to master?
2022-04-29Only avoid pointer casts when using miriGravatar Alice Ryhl 1-2/+13
2022-04-28Fix bugs in `BytesMut::reserve_inner` (#544)Gravatar Jiahao XU 1-1/+1
2022-04-16Make strict provenance compatible (#542)Gravatar Alice Ryhl 1-18/+28
2022-04-15Add TSAN support (#541)Gravatar Alice Ryhl 3-6/+12
2022-04-06Fix aliasing in Clone by using a raw pointer (#523)Gravatar Ben Kimock 1-5/+18
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.
2022-04-06Clarify `BytesMut::unsplit` docs (#535)Gravatar Evan Cameron 1-4/+5
2022-03-25docs: redraw layout diagram with box drawing characters. (#539)Gravatar Anthony Deschamps 1-10/+10
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.
2022-03-16Optimize BytesMut::reserve: Reuse vec if possible (#529)Gravatar Jiahao XU 1-12/+28
* 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>
2022-01-24Implement `Extend<Bytes>` for `BytesMut` (#527)Gravatar Rob Ede 1-0/+11
2022-01-24Address various clippy warnings (#528)Gravatar Rob Ede 3-19/+19
2021-11-24Add `BytesMut::zeroed` (#517)Gravatar Donough Liu 1-0/+17
2021-11-09`const`-ify `Bytes::len` and `Bytes::is_empty` (#514)Gravatar Cyborus04 1-2/+2