pass slices around and not refs to vecs #3404
Merged
+272
−275
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.
It is preferable to pass
&[txs]
around rather than&Vec<>
.This refactoring is extracted from #3385 as that PR is getting a little out of hand.
No functional changes, purely refactoring.
Lots of test code was creating vecs of transactions and we now simply create slices directly.
Edit: The one large implementation change is in
cut_through()
with the "zero allocation" approach.We cannot call
drain()
on the inputs and outputs to chop the cut-through non-copied middle section out. We now need to complete the "copy to start of slice" operation allowing us to then return the shortened slice.We also return the shortened slices as we cannot simply update the slice refs. This requires some lifetimes.
Also use
swap()
here when moving non-cut-through elements to the start of the slice. This effectively resorts the elements of the full slice in a cleaner way, with non-cut-through elements at the start, ready to be sub-sliced.This is an implementation detail but a larger change than majority of this PR.
Edit: I think there may be a way to actually update the refs to the passed in slices, but it does not appear to make the code any easier to read - https://stackoverflow.com/questions/34384089/how-can-i-modify-a-slice-that-is-a-function-parameter