aboutsummaryrefslogtreecommitdiff
path: root/src/yellow/red.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/yellow/red.rs')
-rw-r--r--src/yellow/red.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/yellow/red.rs b/src/yellow/red.rs
index 3fdbfe0c5..3002153ca 100644
--- a/src/yellow/red.rs
+++ b/src/yellow/red.rs
@@ -1,4 +1,7 @@
1use std::sync::{Arc, RwLock}; 1use std::{
2 ptr,
3 sync::RwLock,
4};
2use { 5use {
3 TextUnit, 6 TextUnit,
4 yellow::GreenNode, 7 yellow::GreenNode,
@@ -8,7 +11,7 @@ use {
8pub(crate) struct RedNode { 11pub(crate) struct RedNode {
9 green: GreenNode, 12 green: GreenNode,
10 parent: Option<ParentData>, 13 parent: Option<ParentData>,
11 children: RwLock<Vec<Option<Arc<RedNode>>>>, 14 children: RwLock<Vec<Option<Box<RedNode>>>>,
12} 15}
13 16
14#[derive(Debug)] 17#[derive(Debug)]
@@ -43,7 +46,8 @@ impl RedNode {
43 green: GreenNode, 46 green: GreenNode,
44 parent: Option<ParentData>, 47 parent: Option<ParentData>,
45 ) -> RedNode { 48 ) -> RedNode {
46 let children = vec![None; green.children().len()]; 49 let n_children = green.children().len();
50 let children = (0..n_children).map(|_| None).collect();
47 RedNode { green, parent, children: RwLock::new(children) } 51 RedNode { green, parent, children: RwLock::new(children) }
48 } 52 }
49 53
@@ -62,9 +66,9 @@ impl RedNode {
62 self.green.children().len() 66 self.green.children().len()
63 } 67 }
64 68
65 pub(crate) fn nth_child(&self, idx: usize) -> Arc<RedNode> { 69 pub(crate) fn nth_child(&self, idx: usize) -> ptr::NonNull<RedNode> {
66 match &self.children.read().unwrap()[idx] { 70 match &self.children.read().unwrap()[idx] {
67 Some(child) => return child.clone(), 71 Some(child) => return ptr::NonNull::from(&**child),
68 None => (), 72 None => (),
69 } 73 }
70 let mut children = self.children.write().unwrap(); 74 let mut children = self.children.write().unwrap();
@@ -73,8 +77,9 @@ impl RedNode {
73 let start_offset = self.start_offset() 77 let start_offset = self.start_offset()
74 + green_children[..idx].iter().map(|x| x.text_len()).sum::<TextUnit>(); 78 + green_children[..idx].iter().map(|x| x.text_len()).sum::<TextUnit>();
75 let child = RedNode::new_child(green_children[idx].clone(), self, start_offset, idx); 79 let child = RedNode::new_child(green_children[idx].clone(), self, start_offset, idx);
76 children[idx] = Some(Arc::new(child)) 80 children[idx] = Some(Box::new(child))
77 } 81 }
78 children[idx].as_ref().unwrap().clone() 82 let child = children[idx].as_ref().unwrap();
83 ptr::NonNull::from(&**child)
79 } 84 }
80} 85}