Modifies RawVec reserve
fn structure to improve inlining
#239
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR reorganizes
RawVec::reserve_internal
into a family of methods that allow the compiler to make better inlining decisions.fallible_reserve_internal
is a wrapper aroundreserve_internal
that performs the "do we already have enough space?" check:This portion of the code (which produces a very small amount of assembly) is always inlined. Only if this check fails (which is relatively rare) does it then call
reserve_internal_or_error
, which is not inlined.The
infallible_reserve_internal
/reserve_internal_or_panic
method pair is similar to the above, but also prevents the code needed to detect an error and panic accordingly from being inlined.Collectively, this allows the compiler to inline
Vec::push
andVec::extend*
in more places by transitively shrinking the amount of assembly each produces.You can see the impact in the benchmarks introduced in #235: