sum_tree: Reduce Cursor size for contextless summary types (#38776)
This reduces the size of cursor by a usize when the summary does not
require a context making Cursor usages and constructions slightly more
efficient.
This change is a bit annoying though, as Rust has no means of
specializing, so this uses a `ContextlessSummary` trait with a blanket
impl while turning the `Context` into a GAT `Context<'a>`. This means
`Summary` implies are a bit more verbose now while contextless ones are
slimmer. It does come with the downside that the lifetime in the GAT is
always considered invariant, so some lifetime splitting occurred due to
that.
```
push/4096 time: [352.65 µs 360.87 µs 367.80 µs]
thrpt: [10.621 MiB/s 10.825 MiB/s 11.077 MiB/s]
change:
time: [-2.6633% -1.3640% -0.0561%] (p = 0.05 < 0.05)
thrpt: [+0.0561% +1.3828% +2.7361%]
Change within noise threshold.
Found 16 outliers among 100 measurements (16.00%)
7 (7.00%) low severe
3 (3.00%) low mild
2 (2.00%) high mild
4 (4.00%) high severe
push/65536 time: [1.2917 ms 1.2949 ms 1.2979 ms]
thrpt: [48.156 MiB/s 48.267 MiB/s 48.387 MiB/s]
change:
time: [+1.4428% +1.9844% +2.5299%] (p = 0.00 < 0.05)
thrpt: [-2.4675% -1.9458% -1.4223%]
Performance has regressed.
Found 3 outliers among 100 measurements (3.00%)
1 (1.00%) low severe
1 (1.00%) low mild
1 (1.00%) high severe
append/4096 time: [677.87 ns 678.87 ns 679.83 ns]
thrpt: [5.6112 GiB/s 5.6192 GiB/s 5.6274 GiB/s]
change:
time: [-0.8924% -0.5017% -0.1705%] (p = 0.00 < 0.05)
thrpt: [+0.1708% +0.5043% +0.9004%]
Change within noise threshold.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) low mild
1 (1.00%) high mild
append/65536 time: [9.3275 µs 9.3406 µs 9.3536 µs]
thrpt: [6.5253 GiB/s 6.5344 GiB/s 6.5435 GiB/s]
change:
time: [+0.5409% +0.7215% +0.9054%] (p = 0.00 < 0.05)
thrpt: [-0.8973% -0.7163% -0.5380%]
Change within noise threshold.
slice/4096 time: [27.673 µs 27.791 µs 27.907 µs]
thrpt: [139.97 MiB/s 140.56 MiB/s 141.16 MiB/s]
change:
time: [-1.1065% -0.6725% -0.2429%] (p = 0.00 < 0.05)
thrpt: [+0.2435% +0.6770% +1.1189%]
Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
4 (4.00%) low mild
1 (1.00%) high mild
slice/65536 time: [507.55 µs 517.40 µs 535.60 µs]
thrpt: [116.69 MiB/s 120.80 MiB/s 123.14 MiB/s]
change:
time: [-1.3489% +0.0599% +2.2591%] (p = 0.96 > 0.05)
thrpt: [-2.2092% -0.0598% +1.3674%]
No change in performance detected.
Found 8 outliers among 100 measurements (8.00%)
5 (5.00%) low mild
2 (2.00%) high mild
1 (1.00%) high severe
bytes_in_range/4096 time: [3.3917 µs 3.4108 µs 3.4313 µs]
thrpt: [1.1117 GiB/s 1.1184 GiB/s 1.1247 GiB/s]
change:
time: [-5.3466% -4.7193% -4.1262%] (p = 0.00 < 0.05)
thrpt: [+4.3038% +4.9531% +5.6487%]
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
1 (1.00%) low mild
5 (5.00%) high mild
bytes_in_range/65536 time: [88.175 µs 88.613 µs 89.111 µs]
thrpt: [701.37 MiB/s 705.31 MiB/s 708.82 MiB/s]
change:
time: [-0.6935% +0.3769% +1.4655%] (p = 0.50 > 0.05)
thrpt: [-1.4443% -0.3755% +0.6984%]
No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mild
chars/4096 time: [678.70 ns 680.38 ns 682.08 ns]
thrpt: [5.5927 GiB/s 5.6067 GiB/s 5.6206 GiB/s]
change:
time: [-0.6969% -0.2755% +0.1485%] (p = 0.20 > 0.05)
thrpt: [-0.1483% +0.2763% +0.7018%]
No change in performance detected.
Found 9 outliers among 100 measurements (9.00%)
5 (5.00%) low mild
4 (4.00%) high mild
chars/65536 time: [12.720 µs 12.775 µs 12.830 µs]
thrpt: [4.7573 GiB/s 4.7778 GiB/s 4.7983 GiB/s]
change:
time: [-0.6172% -0.1110% +0.4179%] (p = 0.68 > 0.05)
thrpt: [-0.4162% +0.1112% +0.6211%]
No change in performance detected.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) low mild
1 (1.00%) high mild
clip_point/4096 time: [33.240 µs 33.310 µs 33.394 µs]
thrpt: [116.98 MiB/s 117.27 MiB/s 117.52 MiB/s]
change:
time: [-2.8892% -2.6305% -2.3438%] (p = 0.00 < 0.05)
thrpt: [+2.4000% +2.7015% +2.9751%]
Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
1 (1.00%) low mild
4 (4.00%) high mild
7 (7.00%) high severe
clip_point/65536 time: [1.6531 ms 1.6586 ms 1.6640 ms]
thrpt: [37.560 MiB/s 37.683 MiB/s 37.808 MiB/s]
change:
time: [-6.6381% -5.9395% -5.2680%] (p = 0.00 < 0.05)
thrpt: [+5.5610% +6.3146% +7.1100%]
Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
1 (1.00%) low mild
2 (2.00%) high mild
4 (4.00%) high severe
point_to_offset/4096 time: [11.586 µs 11.603 µs 11.621 µs]
thrpt: [336.15 MiB/s 336.67 MiB/s 337.16 MiB/s]
change:
time: [-14.289% -14.111% -13.939%] (p = 0.00 < 0.05)
thrpt: [+16.197% +16.429% +16.672%]
Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
3 (3.00%) low severe
5 (5.00%) low mild
4 (4.00%) high mild
point_to_offset/65536 time: [527.74 µs 532.08 µs 536.51 µs]
thrpt: [116.49 MiB/s 117.46 MiB/s 118.43 MiB/s]
change:
time: [-6.7825% -4.6235% -2.3533%] (p = 0.00 < 0.05)
thrpt: [+2.4100% +4.8477% +7.2760%]
Performance has improved.
Found 8 outliers among 100 measurements (8.00%)
4 (4.00%) high mild
4 (4.00%) high severe
cursor/4096 time: [16.154 µs 16.192 µs 16.232 µs]
thrpt: [240.66 MiB/s 241.24 MiB/s 241.81 MiB/s]
change:
time: [-3.2536% -2.9145% -2.5526%] (p = 0.00 < 0.05)
thrpt: [+2.6194% +3.0019% +3.3630%]
Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
1 (1.00%) low mild
2 (2.00%) high mild
2 (2.00%) high severe
cursor/65536 time: [509.60 µs 511.24 µs 512.93 µs]
thrpt: [121.85 MiB/s 122.25 MiB/s 122.65 MiB/s]
change:
time: [-7.3677% -6.6017% -5.7840%] (p = 0.00 < 0.05)
thrpt: [+6.1391% +7.0683% +7.9537%]
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
3 (3.00%) high mild
3 (3.00%) high severe
```
Release Notes:
- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -22,7 +22,7 @@ use std::{
|
||||
atomic::{AtomicUsize, Ordering::SeqCst},
|
||||
},
|
||||
};
|
||||
use sum_tree::{Bias, Dimensions, SumTree, Summary, TreeMap};
|
||||
use sum_tree::{Bias, ContextLessSummary, Dimensions, SumTree, TreeMap};
|
||||
use text::{BufferId, Edit};
|
||||
use ui::ElementId;
|
||||
|
||||
@@ -433,7 +433,7 @@ struct TransformSummary {
|
||||
}
|
||||
|
||||
pub struct BlockChunks<'a> {
|
||||
transforms: sum_tree::Cursor<'a, Transform, Dimensions<BlockRow, WrapRow>>,
|
||||
transforms: sum_tree::Cursor<'a, 'static, Transform, Dimensions<BlockRow, WrapRow>>,
|
||||
input_chunks: wrap_map::WrapChunks<'a>,
|
||||
input_chunk: Chunk<'a>,
|
||||
output_row: u32,
|
||||
@@ -443,7 +443,7 @@ pub struct BlockChunks<'a> {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BlockRows<'a> {
|
||||
transforms: sum_tree::Cursor<'a, Transform, Dimensions<BlockRow, WrapRow>>,
|
||||
transforms: sum_tree::Cursor<'a, 'static, Transform, Dimensions<BlockRow, WrapRow>>,
|
||||
input_rows: wrap_map::WrapRows<'a>,
|
||||
output_row: BlockRow,
|
||||
started: bool,
|
||||
@@ -527,7 +527,7 @@ impl BlockMap {
|
||||
|
||||
let mut transforms = self.transforms.borrow_mut();
|
||||
let mut new_transforms = SumTree::default();
|
||||
let mut cursor = transforms.cursor::<WrapRow>(&());
|
||||
let mut cursor = transforms.cursor::<WrapRow>(());
|
||||
let mut last_block_ix = 0;
|
||||
let mut blocks_in_edit = Vec::new();
|
||||
let mut edits = edits.into_iter().peekable();
|
||||
@@ -541,20 +541,20 @@ impl BlockMap {
|
||||
// * Isomorphic transforms that end *at* the start of the edit
|
||||
// * Below blocks that end at the start of the edit
|
||||
// However, if we hit a replace block that ends at the start of the edit we want to reconstruct it.
|
||||
new_transforms.append(cursor.slice(&old_start, Bias::Left), &());
|
||||
new_transforms.append(cursor.slice(&old_start, Bias::Left), ());
|
||||
if let Some(transform) = cursor.item()
|
||||
&& transform.summary.input_rows > 0
|
||||
&& cursor.end() == old_start
|
||||
&& transform.block.as_ref().is_none_or(|b| !b.is_replacement())
|
||||
{
|
||||
// Preserve the transform (push and next)
|
||||
new_transforms.push(transform.clone(), &());
|
||||
new_transforms.push(transform.clone(), ());
|
||||
cursor.next();
|
||||
|
||||
// Preserve below blocks at end of edit
|
||||
while let Some(transform) = cursor.item() {
|
||||
if transform.block.as_ref().is_some_and(|b| b.place_below()) {
|
||||
new_transforms.push(transform.clone(), &());
|
||||
new_transforms.push(transform.clone(), ());
|
||||
cursor.next();
|
||||
} else {
|
||||
break;
|
||||
@@ -720,7 +720,7 @@ impl BlockMap {
|
||||
summary,
|
||||
block: Some(block),
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -731,7 +731,7 @@ impl BlockMap {
|
||||
push_isomorphic(&mut new_transforms, rows_after_last_block, wrap_snapshot);
|
||||
}
|
||||
|
||||
new_transforms.append(cursor.suffix(), &());
|
||||
new_transforms.append(cursor.suffix(), ());
|
||||
debug_assert_eq!(
|
||||
new_transforms.summary().input_rows,
|
||||
wrap_snapshot.max_point().row() + 1
|
||||
@@ -925,11 +925,11 @@ fn push_isomorphic(tree: &mut SumTree<Transform>, rows: u32, wrap_snapshot: &Wra
|
||||
tree.update_last(
|
||||
|last_transform| {
|
||||
if last_transform.block.is_none() {
|
||||
last_transform.summary.add_summary(&summary, &());
|
||||
last_transform.summary.add_summary(&summary);
|
||||
merged = true;
|
||||
}
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
if !merged {
|
||||
tree.push(
|
||||
@@ -937,7 +937,7 @@ fn push_isomorphic(tree: &mut SumTree<Transform>, rows: u32, wrap_snapshot: &Wra
|
||||
summary,
|
||||
block: None,
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -997,7 +997,7 @@ impl BlockMapReader<'_> {
|
||||
.unwrap_or(self.wrap_snapshot.max_point().row() + 1),
|
||||
);
|
||||
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(());
|
||||
cursor.seek(&start_wrap_row, Bias::Left);
|
||||
while let Some(transform) = cursor.item() {
|
||||
if cursor.start().0 > end_wrap_row {
|
||||
@@ -1313,7 +1313,7 @@ impl BlockSnapshot {
|
||||
) -> BlockChunks<'a> {
|
||||
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
|
||||
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&BlockRow(rows.start), Bias::Right);
|
||||
let transform_output_start = cursor.start().0.0;
|
||||
let transform_input_start = cursor.start().1.0;
|
||||
@@ -1345,7 +1345,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub(super) fn row_infos(&self, start_row: BlockRow) -> BlockRows<'_> {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&start_row, Bias::Right);
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = if cursor
|
||||
@@ -1366,7 +1366,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub fn blocks_in_range(&self, rows: Range<u32>) -> impl Iterator<Item = (u32, &Block)> {
|
||||
let mut cursor = self.transforms.cursor::<BlockRow>(&());
|
||||
let mut cursor = self.transforms.cursor::<BlockRow>(());
|
||||
cursor.seek(&BlockRow(rows.start), Bias::Left);
|
||||
while cursor.start().0 < rows.start && cursor.end().0 <= rows.start {
|
||||
cursor.next();
|
||||
@@ -1397,7 +1397,7 @@ impl BlockSnapshot {
|
||||
|
||||
pub fn sticky_header_excerpt(&self, position: f32) -> Option<StickyHeaderExcerpt<'_>> {
|
||||
let top_row = position as u32;
|
||||
let mut cursor = self.transforms.cursor::<BlockRow>(&());
|
||||
let mut cursor = self.transforms.cursor::<BlockRow>(());
|
||||
cursor.seek(&BlockRow(top_row), Bias::Right);
|
||||
|
||||
while let Some(transform) = cursor.item() {
|
||||
@@ -1436,7 +1436,7 @@ impl BlockSnapshot {
|
||||
};
|
||||
let wrap_row = WrapRow(wrap_point.row());
|
||||
|
||||
let mut cursor = self.transforms.cursor::<WrapRow>(&());
|
||||
let mut cursor = self.transforms.cursor::<WrapRow>(());
|
||||
cursor.seek(&wrap_row, Bias::Left);
|
||||
|
||||
while let Some(transform) = cursor.item() {
|
||||
@@ -1464,7 +1464,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub fn longest_row_in_range(&self, range: Range<BlockRow>) -> BlockRow {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let mut longest_row = range.start;
|
||||
@@ -1515,7 +1515,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub(super) fn line_len(&self, row: BlockRow) -> u32 {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&BlockRow(row.0), Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
@@ -1533,13 +1533,13 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub(super) fn is_block_line(&self, row: BlockRow) -> bool {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&row, Bias::Right);
|
||||
cursor.item().is_some_and(|t| t.block.is_some())
|
||||
}
|
||||
|
||||
pub(super) fn is_folded_buffer_header(&self, row: BlockRow) -> bool {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&row, Bias::Right);
|
||||
let Some(transform) = cursor.item() else {
|
||||
return false;
|
||||
@@ -1551,7 +1551,7 @@ impl BlockSnapshot {
|
||||
let wrap_point = self
|
||||
.wrap_snapshot
|
||||
.make_wrap_point(Point::new(row.0, 0), Bias::Left);
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(());
|
||||
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right);
|
||||
cursor.item().is_some_and(|transform| {
|
||||
transform
|
||||
@@ -1562,7 +1562,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&BlockRow(point.row), Bias::Right);
|
||||
|
||||
let max_input_row = WrapRow(self.transforms.summary().input_rows);
|
||||
@@ -1621,7 +1621,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub fn to_block_point(&self, wrap_point: WrapPoint) -> BlockPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(());
|
||||
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_some() {
|
||||
@@ -1639,7 +1639,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
|
||||
pub fn to_wrap_point(&self, block_point: BlockPoint, bias: Bias) -> WrapPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&BlockRow(block_point.row), Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
match transform.block.as_ref() {
|
||||
@@ -1848,19 +1848,17 @@ impl Iterator for BlockRows<'_> {
|
||||
impl sum_tree::Item for Transform {
|
||||
type Summary = TransformSummary;
|
||||
|
||||
fn summary(&self, _cx: &()) -> Self::Summary {
|
||||
fn summary(&self, _cx: ()) -> Self::Summary {
|
||||
self.summary.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for TransformSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for TransformSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &Self, _: &()) {
|
||||
fn add_summary(&mut self, summary: &Self) {
|
||||
if summary.longest_row_chars > self.longest_row_chars {
|
||||
self.longest_row = self.output_rows + summary.longest_row;
|
||||
self.longest_row_chars = summary.longest_row_chars;
|
||||
@@ -1871,21 +1869,21 @@ impl sum_tree::Summary for TransformSummary {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for WrapRow {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += summary.input_rows;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for BlockRow {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += summary.output_rows;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,9 +365,9 @@ impl Default for ItemSummary {
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for ItemSummary {
|
||||
type Context = MultiBufferSnapshot;
|
||||
type Context<'a> = &'a MultiBufferSnapshot;
|
||||
|
||||
fn zero(_cx: &Self::Context) -> Self {
|
||||
fn zero(_cx: Self::Context<'_>) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ impl FoldPoint {
|
||||
pub fn to_inlay_point(self, snapshot: &FoldSnapshot) -> InlayPoint {
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = self.0 - cursor.start().0.0;
|
||||
InlayPoint(cursor.start().1.0 + overshoot)
|
||||
@@ -109,7 +109,7 @@ impl FoldPoint {
|
||||
pub fn to_offset(self, snapshot: &FoldSnapshot) -> FoldOffset {
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, TransformSummary>>(&());
|
||||
.cursor::<Dimensions<FoldPoint, TransformSummary>>(());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = self.0 - cursor.start().1.output.lines;
|
||||
let mut offset = cursor.start().1.output.len;
|
||||
@@ -126,11 +126,11 @@ impl FoldPoint {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += &summary.output.lines;
|
||||
}
|
||||
}
|
||||
@@ -338,9 +338,9 @@ impl FoldMap {
|
||||
},
|
||||
placeholder: None,
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
),
|
||||
inlay_snapshot: inlay_snapshot.clone(),
|
||||
inlay_snapshot: inlay_snapshot,
|
||||
version: 0,
|
||||
fold_metadata_by_id: TreeMap::default(),
|
||||
},
|
||||
@@ -382,7 +382,7 @@ impl FoldMap {
|
||||
if !transform.is_fold() && prev_transform_isomorphic {
|
||||
panic!(
|
||||
"found adjacent isomorphic transforms: {:?}",
|
||||
self.snapshot.transforms.items(&())
|
||||
self.snapshot.transforms.items(())
|
||||
);
|
||||
}
|
||||
prev_transform_isomorphic = !transform.is_fold();
|
||||
@@ -413,7 +413,7 @@ impl FoldMap {
|
||||
let mut inlay_edits_iter = inlay_edits.iter().cloned().peekable();
|
||||
|
||||
let mut new_transforms = SumTree::<Transform>::default();
|
||||
let mut cursor = self.snapshot.transforms.cursor::<InlayOffset>(&());
|
||||
let mut cursor = self.snapshot.transforms.cursor::<InlayOffset>(());
|
||||
cursor.seek(&InlayOffset(0), Bias::Right);
|
||||
|
||||
while let Some(mut edit) = inlay_edits_iter.next() {
|
||||
@@ -423,14 +423,14 @@ impl FoldMap {
|
||||
new_transforms.update_last(
|
||||
|transform| {
|
||||
if !transform.is_fold() {
|
||||
transform.summary.add_summary(&item.summary, &());
|
||||
transform.summary.add_summary(&item.summary, ());
|
||||
cursor.next();
|
||||
}
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
new_transforms.append(cursor.slice(&edit.old.start, Bias::Left), &());
|
||||
new_transforms.append(cursor.slice(&edit.old.start, Bias::Left), ());
|
||||
edit.new.start -= edit.old.start - *cursor.start();
|
||||
edit.old.start = *cursor.start();
|
||||
|
||||
@@ -544,7 +544,7 @@ impl FoldMap {
|
||||
},
|
||||
}),
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -557,7 +557,7 @@ impl FoldMap {
|
||||
}
|
||||
}
|
||||
|
||||
new_transforms.append(cursor.suffix(), &());
|
||||
new_transforms.append(cursor.suffix(), ());
|
||||
if new_transforms.is_empty() {
|
||||
let text_summary = inlay_snapshot.text_summary();
|
||||
push_isomorphic(&mut new_transforms, text_summary);
|
||||
@@ -570,9 +570,9 @@ impl FoldMap {
|
||||
let mut old_transforms = self
|
||||
.snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, FoldOffset>>(&());
|
||||
.cursor::<Dimensions<InlayOffset, FoldOffset>>(());
|
||||
let mut new_transforms =
|
||||
new_transforms.cursor::<Dimensions<InlayOffset, FoldOffset>>(&());
|
||||
new_transforms.cursor::<Dimensions<InlayOffset, FoldOffset>>(());
|
||||
|
||||
for mut edit in inlay_edits {
|
||||
old_transforms.seek(&edit.old.start, Bias::Left);
|
||||
@@ -657,7 +657,7 @@ impl FoldSnapshot {
|
||||
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let start_in_transform = range.start.0 - cursor.start().0.0;
|
||||
@@ -708,7 +708,7 @@ impl FoldSnapshot {
|
||||
pub fn to_fold_point(&self, point: InlayPoint, bias: Bias) -> FoldPoint {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayPoint, FoldPoint>>(&());
|
||||
.cursor::<Dimensions<InlayPoint, FoldPoint>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if cursor.item().is_some_and(|t| t.is_fold()) {
|
||||
if bias == Bias::Left || point == cursor.start().0 {
|
||||
@@ -744,7 +744,7 @@ impl FoldSnapshot {
|
||||
let fold_point = FoldPoint::new(start_row, 0);
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(());
|
||||
cursor.seek(&fold_point, Bias::Left);
|
||||
|
||||
let overshoot = fold_point.0 - cursor.start().0.0;
|
||||
@@ -787,7 +787,7 @@ impl FoldSnapshot {
|
||||
{
|
||||
let buffer_offset = offset.to_offset(&self.inlay_snapshot.buffer);
|
||||
let inlay_offset = self.inlay_snapshot.to_inlay_offset(buffer_offset);
|
||||
let mut cursor = self.transforms.cursor::<InlayOffset>(&());
|
||||
let mut cursor = self.transforms.cursor::<InlayOffset>(());
|
||||
cursor.seek(&inlay_offset, Bias::Right);
|
||||
cursor.item().is_some_and(|t| t.placeholder.is_some())
|
||||
}
|
||||
@@ -796,7 +796,7 @@ impl FoldSnapshot {
|
||||
let mut inlay_point = self
|
||||
.inlay_snapshot
|
||||
.to_inlay_point(Point::new(buffer_row.0, 0));
|
||||
let mut cursor = self.transforms.cursor::<InlayPoint>(&());
|
||||
let mut cursor = self.transforms.cursor::<InlayPoint>(());
|
||||
cursor.seek(&inlay_point, Bias::Right);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
@@ -828,7 +828,7 @@ impl FoldSnapshot {
|
||||
) -> FoldChunks<'a> {
|
||||
let mut transform_cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldOffset, InlayOffset>>(&());
|
||||
.cursor::<Dimensions<FoldOffset, InlayOffset>>(());
|
||||
transform_cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let inlay_start = {
|
||||
@@ -893,7 +893,7 @@ impl FoldSnapshot {
|
||||
pub fn clip_point(&self, point: FoldPoint, bias: Bias) -> FoldPoint {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let transform_start = cursor.start().0.0;
|
||||
@@ -925,7 +925,7 @@ fn push_isomorphic(transforms: &mut SumTree<Transform>, summary: TextSummary) {
|
||||
did_merge = true;
|
||||
}
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
if !did_merge {
|
||||
transforms.push(
|
||||
@@ -936,7 +936,7 @@ fn push_isomorphic(transforms: &mut SumTree<Transform>, summary: TextSummary) {
|
||||
},
|
||||
placeholder: None,
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -946,7 +946,7 @@ fn intersecting_folds<'a>(
|
||||
folds: &'a SumTree<Fold>,
|
||||
range: Range<usize>,
|
||||
inclusive: bool,
|
||||
) -> FilterCursor<'a, impl 'a + FnMut(&FoldSummary) -> bool, Fold, usize> {
|
||||
) -> FilterCursor<'a, 'a, impl 'a + FnMut(&FoldSummary) -> bool, Fold, usize> {
|
||||
let buffer = &inlay_snapshot.buffer;
|
||||
let start = buffer.anchor_before(range.start.to_offset(buffer));
|
||||
let end = buffer.anchor_after(range.end.to_offset(buffer));
|
||||
@@ -1062,19 +1062,17 @@ struct TransformSummary {
|
||||
impl sum_tree::Item for Transform {
|
||||
type Summary = TransformSummary;
|
||||
|
||||
fn summary(&self, _cx: &()) -> Self::Summary {
|
||||
fn summary(&self, _cx: ()) -> Self::Summary {
|
||||
self.summary.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for TransformSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for TransformSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, other: &Self, _: &()) {
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
self.input += &other.input;
|
||||
self.output += &other.output;
|
||||
}
|
||||
@@ -1161,13 +1159,13 @@ impl Default for FoldSummary {
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for FoldSummary {
|
||||
type Context = MultiBufferSnapshot;
|
||||
type Context<'a> = &'a MultiBufferSnapshot;
|
||||
|
||||
fn zero(_cx: &MultiBufferSnapshot) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, other: &Self, buffer: &Self::Context) {
|
||||
fn add_summary(&mut self, other: &Self, buffer: Self::Context<'_>) {
|
||||
if other.min_start.cmp(&self.min_start, buffer) == Ordering::Less {
|
||||
self.min_start = other.min_start;
|
||||
}
|
||||
@@ -1219,7 +1217,7 @@ impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FoldRows<'a> {
|
||||
cursor: Cursor<'a, Transform, Dimensions<FoldPoint, InlayPoint>>,
|
||||
cursor: Cursor<'a, 'static, Transform, Dimensions<FoldPoint, InlayPoint>>,
|
||||
input_rows: InlayBufferRows<'a>,
|
||||
fold_point: FoldPoint,
|
||||
}
|
||||
@@ -1340,7 +1338,7 @@ impl DerefMut for ChunkRendererContext<'_, '_> {
|
||||
}
|
||||
|
||||
pub struct FoldChunks<'a> {
|
||||
transform_cursor: Cursor<'a, Transform, Dimensions<FoldOffset, InlayOffset>>,
|
||||
transform_cursor: Cursor<'a, 'static, Transform, Dimensions<FoldOffset, InlayOffset>>,
|
||||
inlay_chunks: InlayChunks<'a>,
|
||||
inlay_chunk: Option<(InlayOffset, InlayChunk<'a>)>,
|
||||
inlay_offset: InlayOffset,
|
||||
@@ -1488,7 +1486,7 @@ impl FoldOffset {
|
||||
pub fn to_point(self, snapshot: &FoldSnapshot) -> FoldPoint {
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldOffset, TransformSummary>>(&());
|
||||
.cursor::<Dimensions<FoldOffset, TransformSummary>>(());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = if cursor.item().is_none_or(|t| t.is_fold()) {
|
||||
Point::new(0, (self.0 - cursor.start().0.0) as u32)
|
||||
@@ -1504,7 +1502,7 @@ impl FoldOffset {
|
||||
pub fn to_inlay_offset(self, snapshot: &FoldSnapshot) -> InlayOffset {
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldOffset, InlayOffset>>(&());
|
||||
.cursor::<Dimensions<FoldOffset, InlayOffset>>(());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = self.0 - cursor.start().0.0;
|
||||
InlayOffset(cursor.start().1.0 + overshoot)
|
||||
@@ -1534,31 +1532,31 @@ impl Sub for FoldOffset {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldOffset {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += &summary.output.len;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for InlayPoint {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += &summary.input.lines;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for InlayOffset {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += &summary.input.len;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ impl Inlay {
|
||||
impl sum_tree::Item for Transform {
|
||||
type Summary = TransformSummary;
|
||||
|
||||
fn summary(&self, _: &()) -> Self::Summary {
|
||||
fn summary(&self, _: ()) -> Self::Summary {
|
||||
match self {
|
||||
Transform::Isomorphic(summary) => TransformSummary {
|
||||
input: *summary,
|
||||
@@ -128,14 +128,12 @@ struct TransformSummary {
|
||||
output: TextSummary,
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for TransformSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for TransformSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, other: &Self, _: &()) {
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
self.input += &other.input;
|
||||
self.output += &other.output;
|
||||
}
|
||||
@@ -175,11 +173,11 @@ impl SubAssign for InlayOffset {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for InlayOffset {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += &summary.output.len;
|
||||
}
|
||||
}
|
||||
@@ -204,45 +202,45 @@ impl Sub for InlayPoint {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for InlayPoint {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += &summary.output.lines;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for usize {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
*self += &summary.input.len;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for Point {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
*self += &summary.input.lines;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct InlayBufferRows<'a> {
|
||||
transforms: Cursor<'a, Transform, Dimensions<InlayPoint, Point>>,
|
||||
transforms: Cursor<'a, 'static, Transform, Dimensions<InlayPoint, Point>>,
|
||||
buffer_rows: MultiBufferRows<'a>,
|
||||
inlay_row: u32,
|
||||
max_buffer_row: MultiBufferRow,
|
||||
}
|
||||
|
||||
pub struct InlayChunks<'a> {
|
||||
transforms: Cursor<'a, Transform, Dimensions<InlayOffset, usize>>,
|
||||
transforms: Cursor<'a, 'static, Transform, Dimensions<InlayOffset, usize>>,
|
||||
buffer_chunks: CustomHighlightsChunks<'a>,
|
||||
buffer_chunk: Option<Chunk<'a>>,
|
||||
inlay_chunks: Option<text::ChunkWithBitmaps<'a>>,
|
||||
@@ -542,7 +540,7 @@ impl InlayMap {
|
||||
let version = 0;
|
||||
let snapshot = InlaySnapshot {
|
||||
buffer: buffer.clone(),
|
||||
transforms: SumTree::from_iter(Some(Transform::Isomorphic(buffer.text_summary())), &()),
|
||||
transforms: SumTree::from_iter(Some(Transform::Isomorphic(buffer.text_summary())), ()),
|
||||
version,
|
||||
};
|
||||
|
||||
@@ -589,10 +587,10 @@ impl InlayMap {
|
||||
let mut new_transforms = SumTree::default();
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<usize, InlayOffset>>(&());
|
||||
.cursor::<Dimensions<usize, InlayOffset>>(());
|
||||
let mut buffer_edits_iter = buffer_edits.iter().peekable();
|
||||
while let Some(buffer_edit) = buffer_edits_iter.next() {
|
||||
new_transforms.append(cursor.slice(&buffer_edit.old.start, Bias::Left), &());
|
||||
new_transforms.append(cursor.slice(&buffer_edit.old.start, Bias::Left), ());
|
||||
if let Some(Transform::Isomorphic(transform)) = cursor.item()
|
||||
&& cursor.end().0 == buffer_edit.old.start
|
||||
{
|
||||
@@ -642,7 +640,7 @@ impl InlayMap {
|
||||
buffer_snapshot.text_summary_for_range(prefix_start..prefix_end),
|
||||
);
|
||||
|
||||
new_transforms.push(Transform::Inlay(inlay.clone()), &());
|
||||
new_transforms.push(Transform::Inlay(inlay.clone()), ());
|
||||
}
|
||||
|
||||
// Apply the rest of the edit.
|
||||
@@ -674,9 +672,9 @@ impl InlayMap {
|
||||
}
|
||||
}
|
||||
|
||||
new_transforms.append(cursor.suffix(), &());
|
||||
new_transforms.append(cursor.suffix(), ());
|
||||
if new_transforms.is_empty() {
|
||||
new_transforms.push(Transform::Isomorphic(Default::default()), &());
|
||||
new_transforms.push(Transform::Isomorphic(Default::default()), ());
|
||||
}
|
||||
|
||||
drop(cursor);
|
||||
@@ -812,7 +810,7 @@ impl InlaySnapshot {
|
||||
pub fn to_point(&self, offset: InlayOffset) -> InlayPoint {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, InlayPoint, usize>>(&());
|
||||
.cursor::<Dimensions<InlayOffset, InlayPoint, usize>>(());
|
||||
cursor.seek(&offset, Bias::Right);
|
||||
let overshoot = offset.0 - cursor.start().0.0;
|
||||
match cursor.item() {
|
||||
@@ -842,7 +840,7 @@ impl InlaySnapshot {
|
||||
pub fn to_offset(&self, point: InlayPoint) -> InlayOffset {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayPoint, InlayOffset, Point>>(&());
|
||||
.cursor::<Dimensions<InlayPoint, InlayOffset, Point>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
let overshoot = point.0 - cursor.start().0.0;
|
||||
match cursor.item() {
|
||||
@@ -861,7 +859,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
pub fn to_buffer_point(&self, point: InlayPoint) -> Point {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
@@ -873,9 +871,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
pub fn to_buffer_offset(&self, offset: InlayOffset) -> usize {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, usize>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayOffset, usize>>(());
|
||||
cursor.seek(&offset, Bias::Right);
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
@@ -888,9 +884,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
|
||||
pub fn to_inlay_offset(&self, offset: usize) -> InlayOffset {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<usize, InlayOffset>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<usize, InlayOffset>>(());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
@@ -923,7 +917,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
pub fn to_inlay_point(&self, point: Point) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<Point, InlayPoint>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<Point, InlayPoint>>(());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
@@ -957,7 +951,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, mut point: InlayPoint, mut bias: Bias) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
@@ -1054,9 +1048,7 @@ impl InlaySnapshot {
|
||||
pub fn text_summary_for_range(&self, range: Range<InlayOffset>) -> TextSummary {
|
||||
let mut summary = TextSummary::default();
|
||||
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, usize>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayOffset, usize>>(());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let overshoot = range.start.0 - cursor.start().0.0;
|
||||
@@ -1104,7 +1096,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
|
||||
pub fn row_infos(&self, row: u32) -> InlayBufferRows<'_> {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(());
|
||||
let inlay_point = InlayPoint::new(row, 0);
|
||||
cursor.seek(&inlay_point, Bias::Left);
|
||||
|
||||
@@ -1146,9 +1138,7 @@ impl InlaySnapshot {
|
||||
language_aware: bool,
|
||||
highlights: Highlights<'a>,
|
||||
) -> InlayChunks<'a> {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, usize>>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayOffset, usize>>(());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let buffer_range = self.to_buffer_offset(range.start)..self.to_buffer_offset(range.end);
|
||||
@@ -1212,11 +1202,11 @@ fn push_isomorphic(sum_tree: &mut SumTree<Transform>, summary: TextSummary) {
|
||||
*transform += summary.take().unwrap();
|
||||
}
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
|
||||
if let Some(summary) = summary {
|
||||
sum_tree.push(Transform::Isomorphic(summary), &());
|
||||
sum_tree.push(Transform::Isomorphic(summary), ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ pub struct WrapChunks<'a> {
|
||||
input_chunk: Chunk<'a>,
|
||||
output_position: WrapPoint,
|
||||
max_output_row: u32,
|
||||
transforms: Cursor<'a, Transform, Dimensions<WrapPoint, TabPoint>>,
|
||||
transforms: Cursor<'a, 'static, Transform, Dimensions<WrapPoint, TabPoint>>,
|
||||
snapshot: &'a WrapSnapshot,
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ pub struct WrapRows<'a> {
|
||||
output_row: u32,
|
||||
soft_wrapped: bool,
|
||||
max_output_row: u32,
|
||||
transforms: Cursor<'a, Transform, Dimensions<WrapPoint, TabPoint>>,
|
||||
transforms: Cursor<'a, 'static, Transform, Dimensions<WrapPoint, TabPoint>>,
|
||||
}
|
||||
|
||||
impl WrapRows<'_> {
|
||||
@@ -221,7 +221,7 @@ impl WrapMap {
|
||||
if !summary.lines.is_zero() {
|
||||
self.snapshot
|
||||
.transforms
|
||||
.push(Transform::isomorphic(summary), &());
|
||||
.push(Transform::isomorphic(summary), ());
|
||||
}
|
||||
let new_rows = self.snapshot.transforms.summary().output.lines.row + 1;
|
||||
self.snapshot.interpolated = false;
|
||||
@@ -318,7 +318,7 @@ impl WrapSnapshot {
|
||||
let mut transforms = SumTree::default();
|
||||
let extent = tab_snapshot.text_summary();
|
||||
if !extent.lines.is_zero() {
|
||||
transforms.push(Transform::isomorphic(extent), &());
|
||||
transforms.push(Transform::isomorphic(extent), ());
|
||||
}
|
||||
Self {
|
||||
transforms,
|
||||
@@ -336,7 +336,7 @@ impl WrapSnapshot {
|
||||
if tab_edits.is_empty() {
|
||||
new_transforms = self.transforms.clone();
|
||||
} else {
|
||||
let mut old_cursor = self.transforms.cursor::<TabPoint>(&());
|
||||
let mut old_cursor = self.transforms.cursor::<TabPoint>(());
|
||||
|
||||
let mut tab_edits_iter = tab_edits.iter().peekable();
|
||||
new_transforms =
|
||||
@@ -368,7 +368,7 @@ impl WrapSnapshot {
|
||||
|
||||
old_cursor.next();
|
||||
new_transforms
|
||||
.append(old_cursor.slice(&next_edit.old.start, Bias::Right), &());
|
||||
.append(old_cursor.slice(&next_edit.old.start, Bias::Right), ());
|
||||
}
|
||||
} else {
|
||||
if old_cursor.end() > edit.old.end {
|
||||
@@ -378,7 +378,7 @@ impl WrapSnapshot {
|
||||
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
||||
}
|
||||
old_cursor.next();
|
||||
new_transforms.append(old_cursor.suffix(), &());
|
||||
new_transforms.append(old_cursor.suffix(), ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -434,7 +434,7 @@ impl WrapSnapshot {
|
||||
new_transforms = self.transforms.clone();
|
||||
} else {
|
||||
let mut row_edits = row_edits.into_iter().peekable();
|
||||
let mut old_cursor = self.transforms.cursor::<TabPoint>(&());
|
||||
let mut old_cursor = self.transforms.cursor::<TabPoint>(());
|
||||
|
||||
new_transforms = old_cursor.slice(
|
||||
&TabPoint::new(row_edits.peek().unwrap().old_rows.start, 0),
|
||||
@@ -511,7 +511,7 @@ impl WrapSnapshot {
|
||||
if let Some(transform) = edit_transforms.next() {
|
||||
new_transforms.push_or_extend(transform);
|
||||
}
|
||||
new_transforms.extend(edit_transforms, &());
|
||||
new_transforms.extend(edit_transforms, ());
|
||||
|
||||
old_cursor.seek_forward(&TabPoint::new(edit.old_rows.end, 0), Bias::Right);
|
||||
if let Some(next_edit) = row_edits.peek() {
|
||||
@@ -526,7 +526,7 @@ impl WrapSnapshot {
|
||||
new_transforms.append(
|
||||
old_cursor
|
||||
.slice(&TabPoint::new(next_edit.old_rows.start, 0), Bias::Right),
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -537,7 +537,7 @@ impl WrapSnapshot {
|
||||
new_transforms.push_or_extend(Transform::isomorphic(summary));
|
||||
}
|
||||
old_cursor.next();
|
||||
new_transforms.append(old_cursor.suffix(), &());
|
||||
new_transforms.append(old_cursor.suffix(), ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -556,8 +556,8 @@ impl WrapSnapshot {
|
||||
|
||||
fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &WrapSnapshot) -> Patch<u32> {
|
||||
let mut wrap_edits = Vec::with_capacity(tab_edits.len());
|
||||
let mut old_cursor = self.transforms.cursor::<TransformSummary>(&());
|
||||
let mut new_cursor = new_snapshot.transforms.cursor::<TransformSummary>(&());
|
||||
let mut old_cursor = self.transforms.cursor::<TransformSummary>(());
|
||||
let mut new_cursor = new_snapshot.transforms.cursor::<TransformSummary>(());
|
||||
for mut tab_edit in tab_edits.iter().cloned() {
|
||||
tab_edit.old.start.0.column = 0;
|
||||
tab_edit.old.end.0 += Point::new(1, 0);
|
||||
@@ -600,7 +600,7 @@ impl WrapSnapshot {
|
||||
let output_end = WrapPoint::new(rows.end, 0);
|
||||
let mut transforms = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
transforms.seek(&output_start, Bias::Right);
|
||||
let mut input_start = TabPoint(transforms.start().1.0);
|
||||
if transforms.item().is_some_and(|t| t.is_isomorphic()) {
|
||||
@@ -630,7 +630,7 @@ impl WrapSnapshot {
|
||||
pub fn line_len(&self, row: u32) -> u32 {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
cursor.seek(&WrapPoint::new(row + 1, 0), Bias::Left);
|
||||
if cursor
|
||||
.item()
|
||||
@@ -657,7 +657,7 @@ impl WrapSnapshot {
|
||||
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
cursor.seek(&start, Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let start_in_transform = start.0 - cursor.start().0.0;
|
||||
@@ -711,7 +711,7 @@ impl WrapSnapshot {
|
||||
}
|
||||
|
||||
pub fn soft_wrap_indent(&self, row: u32) -> Option<u32> {
|
||||
let mut cursor = self.transforms.cursor::<WrapPoint>(&());
|
||||
let mut cursor = self.transforms.cursor::<WrapPoint>(());
|
||||
cursor.seek(&WrapPoint::new(row + 1, 0), Bias::Right);
|
||||
cursor.item().and_then(|transform| {
|
||||
if transform.is_isomorphic() {
|
||||
@@ -729,7 +729,7 @@ impl WrapSnapshot {
|
||||
pub fn row_infos(&self, start_row: u32) -> WrapRows<'_> {
|
||||
let mut transforms = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left);
|
||||
let mut input_row = transforms.start().1.row();
|
||||
if transforms.item().is_some_and(|t| t.is_isomorphic()) {
|
||||
@@ -751,7 +751,7 @@ impl WrapSnapshot {
|
||||
pub fn to_tab_point(&self, point: WrapPoint) -> TabPoint {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
let mut tab_point = cursor.start().1.0;
|
||||
if cursor.item().is_some_and(|t| t.is_isomorphic()) {
|
||||
@@ -771,14 +771,14 @@ impl WrapSnapshot {
|
||||
pub fn tab_point_to_wrap_point(&self, point: TabPoint) -> WrapPoint {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<TabPoint, WrapPoint>>(&());
|
||||
.cursor::<Dimensions<TabPoint, WrapPoint>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
WrapPoint(cursor.start().1.0 + (point.0 - cursor.start().0.0))
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, mut point: WrapPoint, bias: Bias) -> WrapPoint {
|
||||
if bias == Bias::Left {
|
||||
let mut cursor = self.transforms.cursor::<WrapPoint>(&());
|
||||
let mut cursor = self.transforms.cursor::<WrapPoint>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if cursor.item().is_some_and(|t| !t.is_isomorphic()) {
|
||||
point = *cursor.start();
|
||||
@@ -798,7 +798,7 @@ impl WrapSnapshot {
|
||||
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev();
|
||||
@@ -820,7 +820,7 @@ impl WrapSnapshot {
|
||||
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
while let Some(transform) = cursor.item() {
|
||||
if transform.is_isomorphic() && cursor.start().1.column() == 0 {
|
||||
@@ -857,7 +857,7 @@ impl WrapSnapshot {
|
||||
);
|
||||
|
||||
{
|
||||
let mut transforms = self.transforms.cursor::<()>(&()).peekable();
|
||||
let mut transforms = self.transforms.cursor::<()>(()).peekable();
|
||||
while let Some(transform) = transforms.next() {
|
||||
if let Some(next_transform) = transforms.peek() {
|
||||
assert!(transform.is_isomorphic() != next_transform.is_isomorphic());
|
||||
@@ -1075,7 +1075,7 @@ impl Transform {
|
||||
impl sum_tree::Item for Transform {
|
||||
type Summary = TransformSummary;
|
||||
|
||||
fn summary(&self, _cx: &()) -> Self::Summary {
|
||||
fn summary(&self, _cx: ()) -> Self::Summary {
|
||||
self.summary.clone()
|
||||
}
|
||||
}
|
||||
@@ -1106,11 +1106,11 @@ impl SumTreeExt for SumTree<Transform> {
|
||||
last_transform.summary.output += &transform.summary.output;
|
||||
}
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
|
||||
if let Some(transform) = transform {
|
||||
self.push(transform, &());
|
||||
self.push(transform, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1137,41 +1137,39 @@ impl WrapPoint {
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for TransformSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for TransformSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, other: &Self, _: &()) {
|
||||
fn add_summary(&mut self, other: &Self) {
|
||||
self.input += &other.input;
|
||||
self.output += &other.output;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for TabPoint {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += summary.input.lines;
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::SeekTarget<'_, TransformSummary, TransformSummary> for TabPoint {
|
||||
fn cmp(&self, cursor_location: &TransformSummary, _: &()) -> std::cmp::Ordering {
|
||||
fn cmp(&self, cursor_location: &TransformSummary, _: ()) -> std::cmp::Ordering {
|
||||
Ord::cmp(&self.0, &cursor_location.input.lines)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, TransformSummary> for WrapPoint {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a TransformSummary, _: ()) {
|
||||
self.0 += summary.output.lines;
|
||||
}
|
||||
}
|
||||
@@ -1385,7 +1383,7 @@ mod tests {
|
||||
let mut summary = TextSummary::default();
|
||||
for (ix, item) in wrapped_snapshot
|
||||
.transforms
|
||||
.items(&())
|
||||
.items(())
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user