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

Separate the lifetimes of each input of OrdMap::diff and OrdSet::diff #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SimonSapin
Copy link
Contributor

@SimonSapin SimonSapin commented Dec 23, 2020

This is a breaking change but only for code that uses turbofish syntax on the diff method, the DiffIter type, or the DiffItem type.


Motivation:

We use diff in an algorithm that merges two maps similar to union_with_key, but tries to maximize sharing of internal nodes between similar maps. See "Stage 2" in #166. This works by collecting the results of diff into two Vecs of (key, value) pairs that would need to be inserted in either input map in order to turn it into the desired merge/union. After that is done, we pick the smaller set of updates in order to decide which of the input maps to mutate.

At the moment these Vec contain cloned keys and cloned values. With this PR, they could instead be borrowed with each Vec only borrowing from one of the two input maps. After we’ve decided which Vec to use, only its contents needs to be cloned for inserting into the mutated map.

The full algorithm is at https://foss.heptapod.net/octobus/mercurial-devel/-/commit/53e9ccfaacd492852419cb9dca1abae1765a7474#1e7b6882ee05cf3bc9882ed81b2a0a8dac61ded6_179_182

This is a breaking change but only for code that uses turbofish syntax
on the `diff` method, the `DiffIter` type, or the `DiffItem` type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant