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:
+57
-61
@@ -34,7 +34,7 @@ impl Rope {
|
||||
if self.chunks.is_empty() {
|
||||
return offset == 0;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<usize>(&());
|
||||
let mut cursor = self.chunks.cursor::<usize>(());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
let chunk_offset = offset - cursor.start();
|
||||
cursor
|
||||
@@ -53,7 +53,7 @@ impl Rope {
|
||||
(u8 as i8) >= -0x40
|
||||
}
|
||||
|
||||
let mut cursor = self.chunks.cursor::<usize>(&());
|
||||
let mut cursor = self.chunks.cursor::<usize>(());
|
||||
cursor.seek(&index, Bias::Left);
|
||||
let chunk_offset = index - cursor.start();
|
||||
let lower_idx = cursor.item().map(|chunk| {
|
||||
@@ -85,7 +85,7 @@ impl Rope {
|
||||
(u8 as i8) >= -0x40
|
||||
}
|
||||
|
||||
let mut cursor = self.chunks.cursor::<usize>(&());
|
||||
let mut cursor = self.chunks.cursor::<usize>(());
|
||||
cursor.seek(&index, Bias::Left);
|
||||
let chunk_offset = index - cursor.start();
|
||||
let upper_idx = cursor.item().map(|chunk| {
|
||||
@@ -110,15 +110,15 @@ impl Rope {
|
||||
{
|
||||
self.push_chunk(chunk.as_slice());
|
||||
|
||||
let mut chunks = rope.chunks.cursor::<()>(&());
|
||||
let mut chunks = rope.chunks.cursor::<()>(());
|
||||
chunks.next();
|
||||
chunks.next();
|
||||
self.chunks.append(chunks.suffix(), &());
|
||||
self.chunks.append(chunks.suffix(), ());
|
||||
self.check_invariants();
|
||||
return;
|
||||
}
|
||||
|
||||
self.chunks.append(rope.chunks.clone(), &());
|
||||
self.chunks.append(rope.chunks.clone(), ());
|
||||
self.check_invariants();
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ impl Rope {
|
||||
last_chunk.push_str(suffix);
|
||||
text = remainder;
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
|
||||
if text.len() > 2048 {
|
||||
@@ -190,10 +190,10 @@ impl Rope {
|
||||
|
||||
if new_chunks.len() >= PARALLEL_THRESHOLD {
|
||||
self.chunks
|
||||
.par_extend(new_chunks.into_vec().into_par_iter().map(Chunk::new), &());
|
||||
.par_extend(new_chunks.into_vec().into_par_iter().map(Chunk::new), ());
|
||||
} else {
|
||||
self.chunks
|
||||
.extend(new_chunks.into_iter().map(Chunk::new), &());
|
||||
.extend(new_chunks.into_iter().map(Chunk::new), ());
|
||||
}
|
||||
|
||||
self.check_invariants();
|
||||
@@ -234,10 +234,10 @@ impl Rope {
|
||||
|
||||
if new_chunks.len() >= PARALLEL_THRESHOLD {
|
||||
self.chunks
|
||||
.par_extend(new_chunks.into_par_iter().map(Chunk::new), &());
|
||||
.par_extend(new_chunks.into_par_iter().map(Chunk::new), ());
|
||||
} else {
|
||||
self.chunks
|
||||
.extend(new_chunks.into_iter().map(Chunk::new), &());
|
||||
.extend(new_chunks.into_iter().map(Chunk::new), ());
|
||||
}
|
||||
|
||||
self.check_invariants();
|
||||
@@ -263,11 +263,11 @@ impl Rope {
|
||||
last_chunk.append(suffix);
|
||||
chunk = remainder;
|
||||
},
|
||||
&(),
|
||||
(),
|
||||
);
|
||||
|
||||
if !chunk.is_empty() {
|
||||
self.chunks.push(chunk.into(), &());
|
||||
self.chunks.push(chunk.into(), ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ impl Rope {
|
||||
{
|
||||
// Ensure all chunks except maybe the last one are not underflowing.
|
||||
// Allow some wiggle room for multibyte characters at chunk boundaries.
|
||||
let mut chunks = self.chunks.cursor::<()>(&()).peekable();
|
||||
let mut chunks = self.chunks.cursor::<()>(()).peekable();
|
||||
while let Some(chunk) = chunks.next() {
|
||||
if chunks.peek().is_some() {
|
||||
assert!(chunk.text.len() + 3 >= chunk::MIN_BASE);
|
||||
@@ -295,7 +295,7 @@ impl Rope {
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.chunks.extent(&())
|
||||
self.chunks.extent(())
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
@@ -303,11 +303,11 @@ impl Rope {
|
||||
}
|
||||
|
||||
pub fn max_point(&self) -> Point {
|
||||
self.chunks.extent(&())
|
||||
self.chunks.extent(())
|
||||
}
|
||||
|
||||
pub fn max_point_utf16(&self) -> PointUtf16 {
|
||||
self.chunks.extent(&())
|
||||
self.chunks.extent(())
|
||||
}
|
||||
|
||||
pub fn cursor(&self, offset: usize) -> Cursor<'_> {
|
||||
@@ -351,7 +351,7 @@ impl Rope {
|
||||
if offset >= self.summary().len {
|
||||
return self.summary().len_utf16;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<usize, OffsetUtf16>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<usize, OffsetUtf16>>(());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
let overshoot = offset - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -364,7 +364,7 @@ impl Rope {
|
||||
if offset >= self.summary().len_utf16 {
|
||||
return self.summary().len;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<OffsetUtf16, usize>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<OffsetUtf16, usize>>(());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
let overshoot = offset - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -377,7 +377,7 @@ impl Rope {
|
||||
if offset >= self.summary().len {
|
||||
return self.summary().lines;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<usize, Point>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<usize, Point>>(());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
let overshoot = offset - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -390,7 +390,7 @@ impl Rope {
|
||||
if offset >= self.summary().len {
|
||||
return self.summary().lines_utf16();
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<usize, PointUtf16>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<usize, PointUtf16>>(());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
let overshoot = offset - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -403,7 +403,7 @@ impl Rope {
|
||||
if point >= self.summary().lines {
|
||||
return self.summary().lines_utf16();
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<Point, PointUtf16>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<Point, PointUtf16>>(());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
let overshoot = point - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -416,7 +416,7 @@ impl Rope {
|
||||
if point >= self.summary().lines {
|
||||
return self.summary().len;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<Point, usize>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<Point, usize>>(());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
let overshoot = point - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -437,7 +437,7 @@ impl Rope {
|
||||
if point >= self.summary().lines_utf16() {
|
||||
return self.summary().len;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<PointUtf16, usize>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<PointUtf16, usize>>(());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
let overshoot = point - cursor.start().0;
|
||||
cursor.start().1
|
||||
@@ -450,7 +450,7 @@ impl Rope {
|
||||
if point.0 >= self.summary().lines_utf16() {
|
||||
return self.summary().lines;
|
||||
}
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<PointUtf16, Point>>(&());
|
||||
let mut cursor = self.chunks.cursor::<Dimensions<PointUtf16, Point>>(());
|
||||
cursor.seek(&point.0, Bias::Left);
|
||||
let overshoot = Unclipped(point.0 - cursor.start().0);
|
||||
cursor.start().1
|
||||
@@ -467,7 +467,7 @@ impl Rope {
|
||||
}
|
||||
|
||||
pub fn clip_offset_utf16(&self, offset: OffsetUtf16, bias: Bias) -> OffsetUtf16 {
|
||||
let mut cursor = self.chunks.cursor::<OffsetUtf16>(&());
|
||||
let mut cursor = self.chunks.cursor::<OffsetUtf16>(());
|
||||
cursor.seek(&offset, Bias::Right);
|
||||
if let Some(chunk) = cursor.item() {
|
||||
let overshoot = offset - cursor.start();
|
||||
@@ -478,7 +478,7 @@ impl Rope {
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, point: Point, bias: Bias) -> Point {
|
||||
let mut cursor = self.chunks.cursor::<Point>(&());
|
||||
let mut cursor = self.chunks.cursor::<Point>(());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if let Some(chunk) = cursor.item() {
|
||||
let overshoot = point - cursor.start();
|
||||
@@ -489,7 +489,7 @@ impl Rope {
|
||||
}
|
||||
|
||||
pub fn clip_point_utf16(&self, point: Unclipped<PointUtf16>, bias: Bias) -> PointUtf16 {
|
||||
let mut cursor = self.chunks.cursor::<PointUtf16>(&());
|
||||
let mut cursor = self.chunks.cursor::<PointUtf16>(());
|
||||
cursor.seek(&point.0, Bias::Right);
|
||||
if let Some(chunk) = cursor.item() {
|
||||
let overshoot = Unclipped(point.0 - cursor.start());
|
||||
@@ -564,13 +564,13 @@ impl fmt::Debug for Rope {
|
||||
|
||||
pub struct Cursor<'a> {
|
||||
rope: &'a Rope,
|
||||
chunks: sum_tree::Cursor<'a, Chunk, usize>,
|
||||
chunks: sum_tree::Cursor<'a, 'static, Chunk, usize>,
|
||||
offset: usize,
|
||||
}
|
||||
|
||||
impl<'a> Cursor<'a> {
|
||||
pub fn new(rope: &'a Rope, offset: usize) -> Self {
|
||||
let mut chunks = rope.chunks.cursor(&());
|
||||
let mut chunks = rope.chunks.cursor(());
|
||||
chunks.seek(&offset, Bias::Right);
|
||||
Self {
|
||||
rope,
|
||||
@@ -619,7 +619,7 @@ impl<'a> Cursor<'a> {
|
||||
pub fn summary<D: TextDimension>(&mut self, end_offset: usize) -> D {
|
||||
debug_assert!(end_offset >= self.offset);
|
||||
|
||||
let mut summary = D::zero(&());
|
||||
let mut summary = D::zero(());
|
||||
if let Some(start_chunk) = self.chunks.item() {
|
||||
let start_ix = self.offset - self.chunks.start();
|
||||
let end_ix = cmp::min(end_offset, self.chunks.end()) - self.chunks.start();
|
||||
@@ -640,7 +640,7 @@ impl<'a> Cursor<'a> {
|
||||
}
|
||||
|
||||
pub fn suffix(mut self) -> Rope {
|
||||
self.slice(self.rope.chunks.extent(&()))
|
||||
self.slice(self.rope.chunks.extent(()))
|
||||
}
|
||||
|
||||
pub fn offset(&self) -> usize {
|
||||
@@ -659,7 +659,7 @@ pub struct ChunkBitmaps<'a> {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Chunks<'a> {
|
||||
chunks: sum_tree::Cursor<'a, Chunk, usize>,
|
||||
chunks: sum_tree::Cursor<'a, 'static, Chunk, usize>,
|
||||
range: Range<usize>,
|
||||
offset: usize,
|
||||
reversed: bool,
|
||||
@@ -667,7 +667,7 @@ pub struct Chunks<'a> {
|
||||
|
||||
impl<'a> Chunks<'a> {
|
||||
pub fn new(rope: &'a Rope, range: Range<usize>, reversed: bool) -> Self {
|
||||
let mut chunks = rope.chunks.cursor(&());
|
||||
let mut chunks = rope.chunks.cursor(());
|
||||
let offset = if reversed {
|
||||
chunks.seek(&range.end, Bias::Left);
|
||||
range.end
|
||||
@@ -994,14 +994,14 @@ impl<'a> Iterator for Chunks<'a> {
|
||||
}
|
||||
|
||||
pub struct Bytes<'a> {
|
||||
chunks: sum_tree::Cursor<'a, Chunk, usize>,
|
||||
chunks: sum_tree::Cursor<'a, 'static, Chunk, usize>,
|
||||
range: Range<usize>,
|
||||
reversed: bool,
|
||||
}
|
||||
|
||||
impl<'a> Bytes<'a> {
|
||||
pub fn new(rope: &'a Rope, range: Range<usize>, reversed: bool) -> Self {
|
||||
let mut chunks = rope.chunks.cursor(&());
|
||||
let mut chunks = rope.chunks.cursor(());
|
||||
if reversed {
|
||||
chunks.seek(&range.end, Bias::Left);
|
||||
} else {
|
||||
@@ -1079,7 +1079,7 @@ pub struct Lines<'a> {
|
||||
reversed: bool,
|
||||
}
|
||||
|
||||
impl Lines<'_> {
|
||||
impl<'a> Lines<'a> {
|
||||
pub fn next(&mut self) -> Option<&str> {
|
||||
if self.done {
|
||||
return None;
|
||||
@@ -1144,7 +1144,7 @@ impl Lines<'_> {
|
||||
impl sum_tree::Item for Chunk {
|
||||
type Summary = ChunkSummary;
|
||||
|
||||
fn summary(&self, _cx: &()) -> Self::Summary {
|
||||
fn summary(&self, _cx: ()) -> Self::Summary {
|
||||
ChunkSummary {
|
||||
text: self.as_slice().text_summary(),
|
||||
}
|
||||
@@ -1156,14 +1156,12 @@ pub struct ChunkSummary {
|
||||
text: TextSummary,
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for ChunkSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for ChunkSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &Self, _: &()) {
|
||||
fn add_summary(&mut self, summary: &Self) {
|
||||
self.text += &summary.text;
|
||||
}
|
||||
}
|
||||
@@ -1273,14 +1271,12 @@ impl<'a> From<&'a str> for TextSummary {
|
||||
}
|
||||
}
|
||||
|
||||
impl sum_tree::Summary for TextSummary {
|
||||
type Context = ();
|
||||
|
||||
fn zero(_cx: &()) -> Self {
|
||||
impl sum_tree::ContextLessSummary for TextSummary {
|
||||
fn zero() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &Self, _: &Self::Context) {
|
||||
fn add_summary(&mut self, summary: &Self) {
|
||||
*self += summary;
|
||||
}
|
||||
}
|
||||
@@ -1359,11 +1355,11 @@ impl<D1: TextDimension, D2: TextDimension> TextDimension for Dimensions<D1, D2,
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ChunkSummary> for TextSummary {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: ()) {
|
||||
*self += &summary.text;
|
||||
}
|
||||
}
|
||||
@@ -1383,11 +1379,11 @@ impl TextDimension for TextSummary {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ChunkSummary> for usize {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: ()) {
|
||||
*self += summary.text.len;
|
||||
}
|
||||
}
|
||||
@@ -1407,11 +1403,11 @@ impl TextDimension for usize {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ChunkSummary> for OffsetUtf16 {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: ()) {
|
||||
*self += summary.text.len_utf16;
|
||||
}
|
||||
}
|
||||
@@ -1431,11 +1427,11 @@ impl TextDimension for OffsetUtf16 {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ChunkSummary> for Point {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: ()) {
|
||||
*self += summary.text.lines;
|
||||
}
|
||||
}
|
||||
@@ -1455,11 +1451,11 @@ impl TextDimension for Point {
|
||||
}
|
||||
|
||||
impl<'a> sum_tree::Dimension<'a, ChunkSummary> for PointUtf16 {
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: ()) {
|
||||
*self += summary.text.lines_utf16();
|
||||
}
|
||||
}
|
||||
@@ -1547,14 +1543,14 @@ where
|
||||
K: sum_tree::Dimension<'a, ChunkSummary>,
|
||||
V: sum_tree::Dimension<'a, ChunkSummary>,
|
||||
{
|
||||
fn zero(_cx: &()) -> Self {
|
||||
fn zero(_cx: ()) -> Self {
|
||||
Self {
|
||||
key: K::zero(_cx),
|
||||
value: Some(V::zero(_cx)),
|
||||
}
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _cx: &()) {
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _cx: ()) {
|
||||
self.key.add_summary(summary, _cx);
|
||||
if let Some(value) = &mut self.value {
|
||||
value.add_summary(summary, _cx);
|
||||
@@ -2233,7 +2229,7 @@ mod tests {
|
||||
impl Rope {
|
||||
fn text(&self) -> String {
|
||||
let mut text = String::new();
|
||||
for chunk in self.chunks.cursor::<()>(&()) {
|
||||
for chunk in self.chunks.cursor::<()>(()) {
|
||||
text.push_str(&chunk.text);
|
||||
}
|
||||
text
|
||||
|
||||
@@ -13,12 +13,12 @@ impl<T> From<T> for Unclipped<T> {
|
||||
impl<'a, T: sum_tree::Dimension<'a, ChunkSummary>> sum_tree::Dimension<'a, ChunkSummary>
|
||||
for Unclipped<T>
|
||||
{
|
||||
fn zero(_: &()) -> Self {
|
||||
Self(T::zero(&()))
|
||||
fn zero(_: ()) -> Self {
|
||||
Self(T::zero(()))
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: &()) {
|
||||
self.0.add_summary(summary, &());
|
||||
fn add_summary(&mut self, summary: &'a ChunkSummary, _: ()) {
|
||||
self.0.add_summary(summary, ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user