on master help sign in
fix UB in diff gutter (#7227)
commitde0ef8af15945fb7f761503c615a2d6213d2fd82 authorPascal Kuthe <pascal.kuthe@semimod.de> dateSun 4 Jun 2023, 17:20 (3 years ago) parentd511122
1 file changed+9−9
helix-vcs/src/diff/line_cache.rs+9−9
helix-vcs/src/diff/line_cache.rs+9−9
@@ -20,8 +20,8 @@ use super::{MAX_DIFF_BYTES, MAX_DIFF_LINES};
2020/// A cache that stores the `lines` of a rope as a vector.
2121/// It allows safely reusing the allocation of the vec when updating the rope
2222pub(crate) struct InternedRopeLines {
23− diff_base: Rope,
24− doc: Rope,
23+ diff_base: Box<Rope>,
24+ doc: Box<Rope>,
2525 num_tokens_diff_base: u32,
2626 interned: InternedInput<RopeSlice<'static>>,
2727}
@@ -34,8 +34,8 @@ impl InternedRopeLines {
3434 after: Vec::with_capacity(doc.len_lines()),
3535 interner: Interner::new(diff_base.len_lines() + doc.len_lines()),
3636 },
37− diff_base,
38− doc,
37+ diff_base: Box::new(diff_base),
38+ doc: Box::new(doc),
3939 // will be populated by update_diff_base_impl
4040 num_tokens_diff_base: 0,
4141 };
@@ -44,19 +44,19 @@ impl InternedRopeLines {
4444 }
4545
4646 pub fn doc(&self) -> Rope {
47− self.doc.clone()
47+ Rope::clone(&*self.doc)
4848 }
4949
5050 pub fn diff_base(&self) -> Rope {
51− self.diff_base.clone()
51+ Rope::clone(&*self.diff_base)
5252 }
5353
5454 /// Updates the `diff_base` and optionally the document if `doc` is not None
5555 pub fn update_diff_base(&mut self, diff_base: Rope, doc: Option<Rope>) {
5656 self.interned.clear();
57− self.diff_base = diff_base;
57+ self.diff_base = Box::new(diff_base);
5858 if let Some(doc) = doc {
59− self.doc = doc
59+ self.doc = Box::new(doc)
6060 }
6161 if !self.is_too_large() {
6262 self.update_diff_base_impl();
@@ -74,7 +74,7 @@ impl InternedRopeLines {
7474 .interner
7575 .erase_tokens_after(self.num_tokens_diff_base.into());
7676
77− self.doc = doc;
77+ self.doc = Box::new(doc);
7878 if self.is_too_large() {
7979 self.interned.after.clear();
8080 } else {