aboutsummaryrefslogtreecommitdiff
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-05-28Change Bytes::make_mut to impl From<Bytes> for BytesMut (closes #709) (#710)HEADmasterGravatar Anthony Ramine 2-21/+23
<Arc<T>>::make_mut returns a &mut T, such an API is doable for Bytes too and thus we should reserve Bytes::make_mut for that. Furthermore, it would be helpful to use From<Bytes> as a trait bound in some cases with other traits such as Hyper's body trait, where Hyper gives you Bytes values. Finally, making it impl From<Bytes> for BytesMut means the API is more easily discoverable as it appears on both Bytes and BytesMut.
2024-05-11Offset from (#705)Gravatar Brad Dunbar 3-39/+20
2024-05-05Add zero-copy make_mut (#695)Gravatar Émile Fugulin 2-2/+180
2024-05-05ci: silence unexpected-cfgs warnings due to `#[cfg(loom)]` (#703)Gravatar Alice Ryhl 1-0/+1
2024-04-26Tweak clear and truncate length modifications (#700)Gravatar Alice Ryhl 1-8/+6
2024-04-25Improve BytesMut::split suggestion (#699)Gravatar Paolo Barbolini 1-1/+1
2024-04-25Reuse capacity when possible in <BytesMut as Buf>::advance impl (#698)Gravatar Paolo Barbolini 1-0/+8
2024-04-24Bytes::split_off - check fast path first (#693)Gravatar Brad Dunbar 1-7/+7
Follow up to https://github.com/tokio-rs/bytes/pull/689 * If `at == self.len()`, we already know `at <= self.len()`. * If `at == 0`, we already know `at <= self.len()`.
2024-04-24Resize refactor (#696)Gravatar Brad Dunbar 1-9/+17
* use checked_sub * return when additional == 0 * move safe operation out of unsafe block * use spare_capacity_mut instead of chunk_mut We don't need to check capacity because it's already been reserved above. * Add safety comments * refactor to use guard clauses This would be better written with let-else, but we won't get that until `MSRV >= 1.65.x`. * use if-let instead of unwrap * reduce scope of unsafe blocks Co-authored-by: Alice Ryhl <aliceryhl@google.com> --------- Co-authored-by: Alice Ryhl <aliceryhl@google.com>
2024-04-17Truncate tweaks (#694)Gravatar Brad Dunbar 1-1/+2
2024-04-10perf: improve Bytes::copy_to_bytes (#688)Gravatar tison 1-7/+1
Signed-off-by: tison <wander4096@gmail.com>
2024-04-10Bytes::split_to - check fast path first (#689)Gravatar Brad Dunbar 1-7/+7
If `at == self.len()` then we already know `at <= self.len()`. If `at == 0`, it can't be greater than `self.len()`.
2024-04-09Don't set `len` in `BytesMut::reserve` (#682)Gravatar Brad Dunbar 1-2/+2
A fundamental invariant of `reserve` is that it can extend capacity while the stored data remains the same, even if it's moved to a new allocation. As a result, `len` can never change during a call to `reserve`.
2024-04-08Bytes: Use ManuallyDrop instead of mem::forget (#678)Gravatar Brad Dunbar 1-9/+11
2024-03-14Use ManuallyDrop instead of mem::forget (#675)Gravatar Brad Dunbar 1-14/+12
2024-03-04Remove redundant reserve call (#674)Gravatar Brad Dunbar 1-2/+0
2024-03-03copy_to_bytes: Add panic section to docs (#676)Gravatar Brad Dunbar 1-0/+4
Fixes #454.
2024-03-03Use Iterator from the prelude (#673)Gravatar Brad Dunbar 1-1/+1
CI is [failing][failure] due to unused_imports because Iterator is already in the prelude. Removing it fixes things up. [failure]: https://github.com/tokio-rs/bytes/actions/runs/8034858583/job/21946873895
2024-02-23Refactor split_at/split_to (#663)Gravatar Brad Dunbar 1-26/+24
* set len a little more concisely * inline set_end * remove kind assertions * remove a duplicate assertion * remove redundant assertion and min * rename set_start to advance_unchecked
2024-02-06get_vec_pos: use &self instead of &mut self (#670)Gravatar Brad Dunbar 1-3/+3
I can't see any reason that get_vec_pos needs a &mut self.
2024-02-06set_vec_pos does not need a second parameter (#672)Gravatar Brad Dunbar 1-13/+11
The second argument to `set_vec_pos` always contains the value of `self.data`. Let's just use `self.data` and remove the second parameter altogether.
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.