git: Refactor buffer_diff point translation APIs for more efficient side-by-side diff syncing (#48237)
The side-by-side diff heavily relies on a primitive from `buffer_diff` that converts a point on one side of the diff to a range of points on the other side. The way this primitive is set up on main is pretty naive--every time we call `points_to_base_text_points` (or `base_text_points_to_points`), we need to iterate over all hunks in the diff. That's particularly bad for the case of constructing a new side-by-side diff starting from a multibuffer, because we call those APIs once per excerpt, and the number of excerpts is ~equal to the number of hunks. This PR changes the point translation APIs exposed by `buffer_diff` to make it easier to use them efficiently in `editor`. The new shape is a pair of functions that return a patch that can be used to translate from the main buffer to the base text or vice versa. When syncing edits through the block map that touch several excerpts for the same buffer, we can reuse this patch for excerpts after the first--so when building a new side-by-side diff, we'll iterate over each hunk just once. The shape of the new APIs also sets us up to scale down to cases like editing on the right-hand side of the diff: we can pass in a point range and give them permission to return an approximate patch that's only guaranteed to give the correct results when used with points in that range. For edits that only affect one excerpt, and given how the project diff is set up, that should allow us to skip iterating over most of the hunks in a buffer. Release Notes: - N/A --------- Co-authored-by: cameron <cameron.studdstreet@gmail.com>
This commit is contained in:
1 parent
0d99eb5d40
commit
6d2ed6c3f0
6 files changed
+348
-1615
No files matched your search
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user