-
Notifications
You must be signed in to change notification settings - Fork 286
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
Remove redundant reserve call #674
Conversation
1. put_u8 calls put_slice 2. BytesMut::put_slice calls BytesMut::extend_from_slice 3. BytesMut::extend_from_slice immediately calls reserve
reserve is already inline-able
@@ -1283,9 +1283,7 @@ impl Extend<u8> for BytesMut { | |||
|
|||
// TODO: optimize | |||
// 1. If self.kind() == KIND_VEC, use Vec::extend | |||
// 2. Make `reserve` inline-able |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this TODO comment originally meant, but if it means something like "reserve (in here or put_u8) should be able to omit if the compiler knows the actual length of iter" it may not have been resolved yet.
(In my experience, the compiler optimizations around the reserve have not worked that well.)
EDIT: but seanmonstar who wrote this TODO comment approved this PR, so this is probably not the meaning I have imagined here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with #673 to fix miri tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before accepting this PR, I would like to see a test that calls extend
with an iterator containing more items than the lower limit of the size hint. I'm worried about the panic conditions of put_u8
.
Edit: I guess the behavior is probably okay due to how BytesMut pretends to have an infinite capacity? Still, the test would be good to add to guard against future changes.
@Darksonn Sure thing! Added in 76dae7b. I think the following test technically covers it via |
Note: Miri is currently failing in CI, but is fixed by #673
We're calling
reserve
twice becauseput_u8
already calls it.