Commit Graph
82 Commits
Author SHA1 Message Date
Scott LambandGitHub 141cbc22cb Rename Vtable::to_* -> Vtable::into_* (#776) 2025-03-07 13:58:07 +00:00
hpenneandGitHub 3ab876fee6 Try get methods for Buf trait (#753) 2025-01-21 13:41:42 +01:00
Alice RyhlandGitHub 0ac54ca706 Guarantee address in split_off/split_to for empty slices (#740)
Signed-off-by: Alice Ryhl <[email protected]>
2024-10-18 19:46:49 +02:00
Alice RyhlandGitHub f488be48d0 Revert "Reuse capacity when possible in <BytesMut as Buf>::advance impl" (#726)
This reverts commit baa5053572.
2024-08-01 22:38:17 +02:00
Alice Ryhl f8c7b574c0 Merge 'v1.6.1' into 'master' (#721) 2024-07-13 09:51:48 +02:00
Emily Crandall FleischmanandGitHub 6b4b0eda29 Fix Bytes::is_unique when created from shared BytesMut (#718)
The `is_unique` entry in the vtable for `Bytes` created from a shared
`BytesMut` just called the `shared_is_unique` function from the `bytes`
module. However, that function dereferences the `data` argument` as
`bytes::Shared`, but the actual underlying type is `bytes_mut::Shared`.
2024-07-13 01:09:46 +02:00
Sebastian HahnandGitHub 8cc940779f Allow reclaiming the current allocation (#686) 2024-06-28 14:26:32 +02:00
Paolo BarboliniandGitHub 7a5154ba8b Clarify how BytesMut::zeroed works and advantages to manual impl (#714) 2024-06-21 14:07:25 +02:00
Brad DunbarandGitHub 4950c50376 Offset from (#705) 2024-05-11 19:41:50 +02:00
Émile FugulinandGitHub 86694b0564 Add zero-copy make_mut (#695) 2024-05-05 17:58:00 +02:00
Alice RyhlandGitHub cb7f8449b5 Tweak clear and truncate length modifications (#700) 2024-04-26 09:24:05 +02:00
Paolo BarboliniandGitHub a8806c2457 Improve BytesMut::split suggestion (#699) 2024-04-25 10:43:15 +02:00
Paolo BarboliniandGitHub baa5053572 Reuse capacity when possible in <BytesMut as Buf>::advance impl (#698) 2024-04-25 09:08:16 +02:00
9d3ec1cffb Resize refactor (#696)
* 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 <[email protected]>

---------

Co-authored-by: Alice Ryhl <[email protected]>
2024-04-24 05:49:53 -04:00
Brad DunbarandGitHub 4e2c9c065a Truncate tweaks (#694) 2024-04-17 11:27:00 +02:00
Brad DunbarandGitHub e4af48633c Don't set len in BytesMut::reserve (#682)
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-09 14:35:54 +02:00
Brad DunbarandGitHub 536db06f16 Use ManuallyDrop instead of mem::forget (#675) 2024-03-14 14:40:03 +01:00
Brad DunbarandGitHub 7968f6f83d Remove redundant reserve call (#674) 2024-03-04 09:04:40 +01:00
Brad DunbarandGitHub 99584cc10d Use Iterator from the prelude (#673)
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-03-03 00:40:17 +09:00
Brad DunbarandGitHub 46289278f5 Refactor split_at/split_to (#663)
* 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-23 14:22:58 -08:00
Brad DunbarandGitHub 1bcd2129d1 get_vec_pos: use &self instead of &mut self (#670)
I can't see any reason that get_vec_pos needs a &mut self.
2024-02-06 17:34:30 -05:00
Brad DunbarandGitHub f586ffc525 set_vec_pos does not need a second parameter (#672)
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-06 11:03:37 -08:00
Brad DunbarandGitHub c6972d6132 Calculate original capacity only if necessary (#666)
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-06 10:46:49 -08:00
Brad DunbarandGitHub 47e83056f2 Use sub instead of offset (#668)
We're always subtracting here, and we already have a usize, so `sub`
seems like a more appropriate usage to me.
2024-02-06 10:41:44 -08:00
Brad DunbarandGitHub 8bcac21cb4 Restore commented tests (#665)
These seem to have been commented by accident in #298, and are still
passing.
2024-02-06 10:17:01 -08:00
Brad DunbarandGitHub e24587dd61 Remove unreachable else branch (#661) 2024-01-28 15:30:30 +03:30
Brad DunbarandGitHub 9257a6ea08 Remove an unnecessary else branch (#662) 2024-01-28 14:20:56 +03:30
Brad DunbarandGitHub 0ba3b4c4cd Remove unnecessary namespace qualifier (#660) 2024-01-28 14:07:11 +03:30
Cyborus04andGitHub 0864aea970 add Bytes::is_unique (#643) 2024-01-19 23:59:30 +01:00
Brad DunbarandGitHub abb4a2e66c BytesMut: Assert alignment of Shared (#652)
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-19 11:08:27 +01:00
Gabriel GollerandGitHub 72cbb92e0e docs: fix broken links (#639)
Fixed a few broken links and converted a lot of them from the
html-link to intra-doc links.
2023-11-16 06:24:21 -05:00
Alice RyhlandGitHub fd9243f9e2 Various cleanup (#635) 2023-10-02 15:40:02 +02:00
mxsmandGitHub a4e16a552b docs: fix some spelling mistakes (#633) 2023-09-25 10:47:02 +02:00
Lucas KentandGitHub a14ef4617c Move comment to correct constant (#629) 2023-09-11 11:12:11 +02:00
Michal NazarewiczandGitHub 99a27542a0 Add a safe way to create UninitSlice from slices (#598)
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-09 17:24:23 +01:00
Paa Kojo SamanpaandGitHub 74b04c7aae Mark BytesMut::extend_from_slice as inline (#595)
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-02-04 20:16:41 +01:00
Yotam OfekandGitHub 6e4b1f244b Rename and expose BytesMut::spare_capacity_mut (#572) 2022-10-04 12:23:07 +02:00
Alice RyhlandGitHub d1b5d4ceb1 Don't have important data in unused capacity when calling reserve (#563) 2022-08-12 12:22:43 +02:00
Matt SchulteandGitHub d6e1999d97 Fix reserve over allocating underlying buffer (#560)
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-30 11:16:32 +02:00
7553a67be2 Fix amortized asymptotics of BytesMut (#555)
Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: Frank Steffahn <[email protected]>
2022-07-19 13:17:53 +02:00
cd188cbd67 Add conversion from Bytes to Vec<u8> (#547)
Signed-off-by: Jiahao XU <[email protected]>
Co-authored-by: Alice Ryhl <[email protected]>
2022-07-13 09:04:23 +02:00
Jiahao XUandGitHub 10d1f6ec5c Fix: From<BytesMut> fo Vec<u8> implementation (#554)
Signed-off-by: Jiahao XU <[email protected]>
2022-07-13 08:59:54 +02:00
Jiahao XUandGitHub 068ed41bc0 Add conversion from BytesMut to Vec<u8> (#543) 2022-07-10 12:44:29 +02:00
Alice RyhlandGitHub f514bd38da miri: don't use int2ptr casts for invalid pointers (#553) 2022-07-09 21:54:34 +02:00
Jiahao XUandGitHub 0a2c43af88 Fix bugs in BytesMut::reserve_inner (#544) 2022-04-28 11:37:33 +02:00
Alice RyhlandGitHub 547a32033e Add TSAN support (#541) 2022-04-15 22:46:40 +02:00
Evan CameronandGitHub 9e6edd18d2 Clarify BytesMut::unsplit docs (#535) 2022-04-06 15:19:00 +02:00
Jiahao XUandGitHub d4f5023383 Optimize BytesMut::reserve: Reuse vec if possible (#529)
* 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 <[email protected]>
2022-03-16 10:11:42 -04:00
Rob EdeandGitHub 131dae161f Implement Extend<Bytes> for BytesMut (#527) 2022-01-24 09:58:18 +01:00
Rob EdeandGitHub 0e3b2466f1 Address various clippy warnings (#528) 2022-01-24 09:58:05 +01:00