aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2024-05-28Change Bytes::make_mut to impl From<Bytes> for BytesMut (closes #709) (#710)HEADmasterGravatar Anthony Ramine 4-52/+54
<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-19Fix iter tests to use the actual bytes IntoIter instead of std (#707)Gravatar Paolo Barbolini 1-4/+4
2024-05-11Offset from (#705)Gravatar Brad Dunbar 3-39/+20
2024-05-05Add zero-copy make_mut (#695)Gravatar Émile Fugulin 4-2/+341
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-11test(benches): encloses bytes into `test::black_box` for clone benches (#691)Gravatar Joseph Perez 1-3/+3
Closes #690 Without it, it seems to me that compiler is able to inline the vtable, resulting in similar results for `clone_shared` and `clone_arg_vec`.
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-22chore: prepare bytes v1.6.0 (#681)v1.6.0Gravatar Brad Dunbar 2-1/+38
2024-03-14Use ManuallyDrop instead of mem::forget (#675)Gravatar Brad Dunbar 1-14/+12
2024-03-04Remove commented tests for Bytes::unsplit (#677)Gravatar Brad Dunbar 1-91/+0
Bytes doesn't have an unsplit method anymore. We can always retrieve these from git history if necessary.
2024-03-04Remove redundant reserve call (#674)Gravatar Brad Dunbar 2-2/+22
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 3-0/+84
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.
2024-01-08Update CI config (#650)Gravatar Taiki Endo 4-30/+33
2024-01-08Update loom to 0.7 (#651)Gravatar Taiki Endo 1-1/+1
2024-01-03readme: add security policy (#649)Gravatar Alice Ryhl 1-0/+9
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 8-137/+351
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-09-07doc: fix changelog typo (#628)Gravatar Alice Ryhl 1-1/+1
2023-09-07chore: prepare bytes v1.5.0 (#627)v1.5.0Gravatar Alice Ryhl 2-1/+12
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-06-05Fix CI failure (#616)Gravatar Taiki Endo 2-0/+2
2023-02-10Implement BufMut for `&mut [MaybeUninit<u8>]` (#597)Gravatar Michal Nazarewicz 2-13/+145
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