From 83acbc06bd01cd7045566170148e2150f568f77c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Jul 2018 02:39:26 +0300 Subject: No need to Arc reds, they are rooted anyways --- src/yellow/red.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/yellow/red.rs') 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 @@ -use std::sync::{Arc, RwLock}; +use std::{ + ptr, + sync::RwLock, +}; use { TextUnit, yellow::GreenNode, @@ -8,7 +11,7 @@ use { pub(crate) struct RedNode { green: GreenNode, parent: Option, - children: RwLock>>>, + children: RwLock>>>, } #[derive(Debug)] @@ -43,7 +46,8 @@ impl RedNode { green: GreenNode, parent: Option, ) -> RedNode { - let children = vec![None; green.children().len()]; + let n_children = green.children().len(); + let children = (0..n_children).map(|_| None).collect(); RedNode { green, parent, children: RwLock::new(children) } } @@ -62,9 +66,9 @@ impl RedNode { self.green.children().len() } - pub(crate) fn nth_child(&self, idx: usize) -> Arc { + pub(crate) fn nth_child(&self, idx: usize) -> ptr::NonNull { match &self.children.read().unwrap()[idx] { - Some(child) => return child.clone(), + Some(child) => return ptr::NonNull::from(&**child), None => (), } let mut children = self.children.write().unwrap(); @@ -73,8 +77,9 @@ impl RedNode { let start_offset = self.start_offset() + green_children[..idx].iter().map(|x| x.text_len()).sum::(); let child = RedNode::new_child(green_children[idx].clone(), self, start_offset, idx); - children[idx] = Some(Arc::new(child)) + children[idx] = Some(Box::new(child)) } - children[idx].as_ref().unwrap().clone() + let child = children[idx].as_ref().unwrap(); + ptr::NonNull::from(&**child) } } -- cgit v1.2.3