aboutsummaryrefslogtreecommitdiff
path: root/src/yellow/red.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-30 10:44:14 +0100
committerAleksey Kladov <[email protected]>2018-07-30 10:44:14 +0100
commita2a810f118bb2ec541f852bf02eebdf02c7326f7 (patch)
tree1b48a5b2f10e0f4a706e496eabd27e8490c332be /src/yellow/red.rs
parent423298dddd50d28ce891b10695417401226235a3 (diff)
Add parent links
Diffstat (limited to 'src/yellow/red.rs')
-rw-r--r--src/yellow/red.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/yellow/red.rs b/src/yellow/red.rs
index 3002153ca..e0fa27e5f 100644
--- a/src/yellow/red.rs
+++ b/src/yellow/red.rs
@@ -16,7 +16,7 @@ pub(crate) struct RedNode {
16 16
17#[derive(Debug)] 17#[derive(Debug)]
18struct ParentData { 18struct ParentData {
19 parent: *const RedNode, 19 parent: ptr::NonNull<RedNode>,
20 start_offset: TextUnit, 20 start_offset: TextUnit,
21 index_in_parent: usize, 21 index_in_parent: usize,
22} 22}
@@ -30,7 +30,7 @@ impl RedNode {
30 30
31 fn new_child( 31 fn new_child(
32 green: GreenNode, 32 green: GreenNode,
33 parent: *const RedNode, 33 parent: ptr::NonNull<RedNode>,
34 start_offset: TextUnit, 34 start_offset: TextUnit,
35 index_in_parent: usize, 35 index_in_parent: usize,
36 ) -> RedNode { 36 ) -> RedNode {
@@ -76,10 +76,14 @@ impl RedNode {
76 let green_children = self.green.children(); 76 let green_children = self.green.children();
77 let start_offset = self.start_offset() 77 let start_offset = self.start_offset()
78 + green_children[..idx].iter().map(|x| x.text_len()).sum::<TextUnit>(); 78 + green_children[..idx].iter().map(|x| x.text_len()).sum::<TextUnit>();
79 let child = RedNode::new_child(green_children[idx].clone(), self, start_offset, idx); 79 let child = RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx);
80 children[idx] = Some(Box::new(child)) 80 children[idx] = Some(Box::new(child))
81 } 81 }
82 let child = children[idx].as_ref().unwrap(); 82 let child = children[idx].as_ref().unwrap();
83 ptr::NonNull::from(&**child) 83 ptr::NonNull::from(&**child)
84 } 84 }
85
86 pub(crate) fn parent(&self) -> Option<ptr::NonNull<RedNode>> {
87 Some(self.parent.as_ref()?.parent)
88 }
85} 89}