on master help sign in
fix UB in diff gutter (#7227)
de0ef8aPascal Kuthe
helix-vcs/src/diff/line_cache.rs+9−9
@@ -20,8 +20,8 @@ use super::{MAX_DIFF_BYTES, MAX_DIFF_LINES};
20/// A cache that stores the `lines` of a rope as a vector.
20/// A cache that stores the `lines` of a rope as a vector.
21/// It allows safely reusing the allocation of the vec when updating the rope
21/// It allows safely reusing the allocation of the vec when updating the rope
22pub(crate) struct InternedRopeLines {
22pub(crate) struct InternedRopeLines {
23− diff_base: Rope,
23+ diff_base: Box<Rope>,
24− doc: Rope,
24+ doc: Box<Rope>,
25 num_tokens_diff_base: u32,
25 num_tokens_diff_base: u32,
26 interned: InternedInput<RopeSlice<'static>>,
26 interned: InternedInput<RopeSlice<'static>>,
27}
27}
@@ -34,8 +34,8 @@ impl InternedRopeLines {
34 after: Vec::with_capacity(doc.len_lines()),
34 after: Vec::with_capacity(doc.len_lines()),
35 interner: Interner::new(diff_base.len_lines() + doc.len_lines()),
35 interner: Interner::new(diff_base.len_lines() + doc.len_lines()),
36 },
36 },
37− diff_base,
37+ diff_base: Box::new(diff_base),
38− doc,
38+ doc: Box::new(doc),
39 // will be populated by update_diff_base_impl
39 // will be populated by update_diff_base_impl
40 num_tokens_diff_base: 0,
40 num_tokens_diff_base: 0,
41 };
41 };
@@ -44,19 +44,19 @@ impl InternedRopeLines {
44 }
44 }
45
45
46 pub fn doc(&self) -> Rope {
46 pub fn doc(&self) -> Rope {
47− self.doc.clone()
47+ Rope::clone(&*self.doc)
48 }
48 }
49
49
50 pub fn diff_base(&self) -> Rope {
50 pub fn diff_base(&self) -> Rope {
51− self.diff_base.clone()
51+ Rope::clone(&*self.diff_base)
52 }
52 }
53
53
54 /// Updates the `diff_base` and optionally the document if `doc` is not None
54 /// Updates the `diff_base` and optionally the document if `doc` is not None
55 pub fn update_diff_base(&mut self, diff_base: Rope, doc: Option<Rope>) {
55 pub fn update_diff_base(&mut self, diff_base: Rope, doc: Option<Rope>) {
56 self.interned.clear();
56 self.interned.clear();
57− self.diff_base = diff_base;
57+ self.diff_base = Box::new(diff_base);
58 if let Some(doc) = doc {
58 if let Some(doc) = doc {
59− self.doc = doc
59+ self.doc = Box::new(doc)
60 }
60 }
61 if !self.is_too_large() {
61 if !self.is_too_large() {
62 self.update_diff_base_impl();
62 self.update_diff_base_impl();
@@ -74,7 +74,7 @@ impl InternedRopeLines {
74 .interner
74 .interner
75 .erase_tokens_after(self.num_tokens_diff_base.into());
75 .erase_tokens_after(self.num_tokens_diff_base.into());
76
76
77− self.doc = doc;
77+ self.doc = Box::new(doc);
78 if self.is_too_large() {
78 if self.is_too_large() {
79 self.interned.after.clear();
79 self.interned.after.clear();
80 } else {
80 } else {