-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BytesMut fails to reuse buffer in trivial case where all data has been consumed #412
Comments
Yea, this does seem wrong. In this test, |
For the first half of the condition, we want to be checking if there's enough space to satisfy the allocation: For the second half, we shouldn't actually do the |
I don't know why the second half of that branch exists at all (Maybe @carllerche remembers?). We can't use just |
I don't believe |
I just wrote up a comment describing |
Requiring |
The following test fails with bytes 0.5.5:
I would expect this test to pass, as we should be able to reuse the entire buffer given that there is only one reference, and that since we've consumed the entire buffer there should be no data to copy.
The issue appears to come from this condition here:
https://github.com/tokio-rs/bytes/blob/master/src/bytes_mut.rs#L562-L564
Here,
additional
refers to the value passed to reserve - this is the amount of data above the current length, but here we require that the current offset be beyond that, for some reason - perhaps this is meant to be checking againstadditional - capacity
? Additionally, this does not take into account the amount of data that we need to copy - ifself.len() == 0
then the copy is free and we should always take this option.The text was updated successfully, but these errors were encountered: