diff options
Diffstat (limited to 'src/yellow/red.rs')
-rw-r--r-- | src/yellow/red.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/yellow/red.rs b/src/yellow/red.rs index f57c4a9b7..13ad44c65 100644 --- a/src/yellow/red.rs +++ b/src/yellow/red.rs | |||
@@ -1,7 +1,5 @@ | |||
1 | use std::ptr; | ||
2 | |||
3 | use parking_lot::RwLock; | 1 | use parking_lot::RwLock; |
4 | use {yellow::GreenNode, TextUnit}; | 2 | use {yellow::{GreenNode, RedPtr}, TextUnit}; |
5 | 3 | ||
6 | #[derive(Debug)] | 4 | #[derive(Debug)] |
7 | pub(crate) struct RedNode { | 5 | pub(crate) struct RedNode { |
@@ -12,7 +10,7 @@ pub(crate) struct RedNode { | |||
12 | 10 | ||
13 | #[derive(Debug)] | 11 | #[derive(Debug)] |
14 | struct ParentData { | 12 | struct ParentData { |
15 | parent: ptr::NonNull<RedNode>, | 13 | parent: RedPtr, |
16 | start_offset: TextUnit, | 14 | start_offset: TextUnit, |
17 | index_in_parent: usize, | 15 | index_in_parent: usize, |
18 | } | 16 | } |
@@ -24,7 +22,7 @@ impl RedNode { | |||
24 | 22 | ||
25 | fn new_child( | 23 | fn new_child( |
26 | green: GreenNode, | 24 | green: GreenNode, |
27 | parent: ptr::NonNull<RedNode>, | 25 | parent: RedPtr, |
28 | start_offset: TextUnit, | 26 | start_offset: TextUnit, |
29 | index_in_parent: usize, | 27 | index_in_parent: usize, |
30 | ) -> RedNode { | 28 | ) -> RedNode { |
@@ -64,12 +62,12 @@ impl RedNode { | |||
64 | self.green.children().len() | 62 | self.green.children().len() |
65 | } | 63 | } |
66 | 64 | ||
67 | pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> { | 65 | pub(crate) fn get_child(&self, idx: usize) -> Option<RedPtr> { |
68 | if idx >= self.n_children() { | 66 | if idx >= self.n_children() { |
69 | return None; | 67 | return None; |
70 | } | 68 | } |
71 | match &self.children.read()[idx] { | 69 | match &self.children.read()[idx] { |
72 | Some(child) => return Some(child.into()), | 70 | Some(child) => return Some(RedPtr::new(child)), |
73 | None => (), | 71 | None => (), |
74 | }; | 72 | }; |
75 | let green_children = self.green.children(); | 73 | let green_children = self.green.children(); |
@@ -79,15 +77,15 @@ impl RedNode { | |||
79 | .map(|x| x.text_len()) | 77 | .map(|x| x.text_len()) |
80 | .sum::<TextUnit>(); | 78 | .sum::<TextUnit>(); |
81 | let child = | 79 | let child = |
82 | RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx); | 80 | RedNode::new_child(green_children[idx].clone(), RedPtr::new(self), start_offset, idx); |
83 | let mut children = self.children.write(); | 81 | let mut children = self.children.write(); |
84 | if children[idx].is_none() { | 82 | if children[idx].is_none() { |
85 | children[idx] = Some(child) | 83 | children[idx] = Some(child) |
86 | } | 84 | } |
87 | Some(children[idx].as_ref().unwrap().into()) | 85 | Some(RedPtr::new(children[idx].as_ref().unwrap())) |
88 | } | 86 | } |
89 | 87 | ||
90 | pub(crate) fn parent(&self) -> Option<ptr::NonNull<RedNode>> { | 88 | pub(crate) fn parent(&self) -> Option<RedPtr> { |
91 | Some(self.parent.as_ref()?.parent) | 89 | Some(self.parent.as_ref()?.parent) |
92 | } | 90 | } |
93 | pub(crate) fn index_in_parent(&self) -> Option<usize> { | 91 | pub(crate) fn index_in_parent(&self) -> Option<usize> { |