tokio-rs / bytes

Utilities for working with bytes
MIT License
1.89k stars 284 forks source link

Add zero-copy make_mut #695

Closed Sytten closed 5 months ago

Sytten commented 6 months ago

Supersede https://github.com/tokio-rs/bytes/pull/687 Closes https://github.com/tokio-rs/bytes/issues/611

This is my first time contributing to bytes and this is quite a change, do let me know if you want more tests.

mattfbacon commented 6 months ago

Why is x.make_mut() not the same as x.try_into_mut().unwrap_or_else(|| BytesMut::from(&*x))?

Sytten commented 6 months ago

I mean I guess we could but we already have to handle the copy case in each to_mut vtable function so I dont really see the point in not using that. Plus it there is a small chance that a concurrent thread released the shared since we use acquire vs relaxed ordering.

Sytten commented 5 months ago

Sorry I didnt have to work on it more, I will try this week. @braddunbar if you have for a review I would appreciate 🙏

braddunbar commented 5 months ago

Oh, I missed the notification. Thanks for the ping! I'll take a look.

Sytten commented 5 months ago

@braddunbar @Darksonn Gentle ping :) I added the comment and an odd test. Let me know if we want to add more tests.

Sytten commented 5 months ago

@Darksonn Done the improvements

Sytten commented 5 months ago

@braddunbar @Darksonn Ready for another round :)