Skip to content
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

pass slices around and not refs to vecs #3404

Merged
merged 3 commits into from
Jul 27, 2020

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Jul 26, 2020

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

@antiochp
Copy link
Member Author

Going to merge. This is just a refactor, no behavior changes.

@antiochp antiochp merged commit 80841f1 into mimblewimble:master Jul 27, 2020
@antiochp antiochp deleted the slices_everywhere branch July 27, 2020 10:07
@antiochp antiochp mentioned this pull request Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant