diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 9a35a61de3..bb796ace93 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -2105,7 +2105,7 @@ impl sum_tree::Item for Fragment { impl sum_tree::Summary for FragmentSummary { type Context = (); - fn add_summary(&mut self, other: &Self) { + fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) { self.text_summary += &other.text_summary; debug_assert!(self.max_fragment_id <= other.max_fragment_id); self.max_fragment_id = other.max_fragment_id.clone(); @@ -2171,7 +2171,7 @@ impl sum_tree::Item for InsertionSplit { impl sum_tree::Summary for InsertionSplitSummary { type Context = (); - fn add_summary(&mut self, other: &Self) { + fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) { self.extent += other.extent; } } diff --git a/zed/src/editor/buffer/text.rs b/zed/src/editor/buffer/text.rs index 02f584a395..140fe2257e 100644 --- a/zed/src/editor/buffer/text.rs +++ b/zed/src/editor/buffer/text.rs @@ -61,7 +61,7 @@ pub struct TextSummary { impl sum_tree::Summary for TextSummary { type Context = (); - fn add_summary(&mut self, other: &Self) { + fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) { *self += other; } } diff --git a/zed/src/editor/display_map/fold_map.rs b/zed/src/editor/display_map/fold_map.rs index 21d033ce64..c2892fa1d3 100644 --- a/zed/src/editor/display_map/fold_map.rs +++ b/zed/src/editor/display_map/fold_map.rs @@ -459,7 +459,7 @@ impl sum_tree::Item for Transform { impl sum_tree::Summary for TransformSummary { type Context = (); - fn add_summary(&mut self, other: &Self) { + fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) { self.buffer += &other.buffer; self.display += &other.display; } @@ -467,7 +467,7 @@ impl sum_tree::Summary for TransformSummary { impl<'a> sum_tree::Dimension<'a, TransformSummary> for TransformSummary { fn add_summary(&mut self, summary: &'a TransformSummary) { - sum_tree::Summary::add_summary(self, summary); + sum_tree::Summary::add_summary(self, summary, None); } } @@ -512,7 +512,7 @@ impl Default for FoldSummary { impl sum_tree::Summary for FoldSummary { type Context = Buffer; - fn add_summary_with_ctx(&mut self, other: &Self, buffer: Option<&Self::Context>) { + fn add_summary(&mut self, other: &Self, buffer: Option<&Self::Context>) { let buffer = buffer.unwrap(); if other.min_start.cmp(&self.min_start, buffer).unwrap() == Ordering::Less { self.min_start = other.min_start.clone(); diff --git a/zed/src/operation_queue.rs b/zed/src/operation_queue.rs index 27b0550b76..e70d91b6cb 100644 --- a/zed/src/operation_queue.rs +++ b/zed/src/operation_queue.rs @@ -68,7 +68,7 @@ impl KeyedItem for T { impl Summary for OperationSummary { type Context = (); - fn add_summary(&mut self, other: &Self) { + fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) { assert!(self.key < other.key); self.key = other.key; self.len += other.len; diff --git a/zed/src/sum_tree/cursor.rs b/zed/src/sum_tree/cursor.rs index 44647ceb37..d90702ab6e 100644 --- a/zed/src/sum_tree/cursor.rs +++ b/zed/src/sum_tree/cursor.rs @@ -560,7 +560,7 @@ where slice_items_summary .as_mut() .unwrap() - .add_summary_with_ctx(item_summary, ctx); + .add_summary(item_summary, ctx); } SeekAggregate::Summary(summary) => { summary.add_summary(item_summary); @@ -679,7 +679,7 @@ where slice_items_summary .as_mut() .unwrap() - .add_summary_with_ctx(item_summary, ctx); + .add_summary(item_summary, ctx); slice_item_summaries.push(item_summary.clone()); } SeekAggregate::Summary(summary) => { diff --git a/zed/src/sum_tree/mod.rs b/zed/src/sum_tree/mod.rs index 0c85eaa8ef..375e2d7e2a 100644 --- a/zed/src/sum_tree/mod.rs +++ b/zed/src/sum_tree/mod.rs @@ -25,14 +25,7 @@ pub trait KeyedItem: Item { pub trait Summary: Default + Clone + fmt::Debug { type Context; - fn add_summary(&mut self, _summary: &Self) { - unimplemented!(); - } - - fn add_summary_with_ctx(&mut self, summary: &Self, ctx: Option<&Self::Context>) { - assert!(ctx.is_none()); - self.add_summary(summary); - } + fn add_summary(&mut self, summary: &Self, ctx: Option<&Self::Context>); } pub trait Dimension<'a, S: Summary>: Clone + fmt::Debug + Default { @@ -134,6 +127,13 @@ impl SumTree { } pub fn extend(&mut self, iter: I) + where + I: IntoIterator, + { + self.extend_with_ctx(iter, None) + } + + pub fn extend_with_ctx(&mut self, iter: I, ctx: Option<&::Context>) where I: IntoIterator, { @@ -159,7 +159,7 @@ impl SumTree { }) = leaf.as_mut() { let item_summary = item.summary(); - summary.add_summary(&item_summary); + summary.add_summary(&item_summary, ctx); items.push(item); item_summaries.push(item_summary); } else { @@ -226,7 +226,7 @@ impl SumTree { .. } => { let other_node = other.0.clone(); - summary.add_summary_with_ctx(other_node.summary(), ctx); + summary.add_summary(other_node.summary(), ctx); let height_delta = *height - other_node.height(); let mut summaries_to_append = ArrayVec::<[T::Summary; 2 * TREE_BASE]>::new(); @@ -323,7 +323,7 @@ impl SumTree { item_summaries: right_summaries, }))) } else { - summary.add_summary_with_ctx(other_node.summary(), ctx); + summary.add_summary(other_node.summary(), ctx); items.extend(other_node.items().iter().cloned()); item_summaries.extend(other_node.child_summaries().iter().cloned()); None @@ -538,7 +538,7 @@ where { let mut sum = T::default(); for value in iter { - sum.add_summary_with_ctx(value, ctx); + sum.add_summary(value, ctx); } sum } @@ -889,7 +889,7 @@ mod tests { impl Summary for IntegersSummary { type Context = (); - fn add_summary(&mut self, other: &Self) { + fn add_summary(&mut self, other: &Self, _: Option<&Self::Context>) { self.count.0 += &other.count.0; self.sum.0 += &other.sum.0; self.contains_even |= other.contains_even; diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index eb5172d577..2c16833395 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -538,7 +538,7 @@ impl Default for EntrySummary { impl sum_tree::Summary for EntrySummary { type Context = (); - fn add_summary(&mut self, rhs: &Self) { + fn add_summary(&mut self, rhs: &Self, _: Option<&Self::Context>) { self.max_path = rhs.max_path.clone(); self.file_count += rhs.file_count; self.visible_file_count += rhs.visible_file_count;