aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs1
-rw-r--r--src/yellow/red.rs23
2 files changed, 13 insertions, 11 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a7705ab66..94d843db3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -24,6 +24,7 @@ extern crate itertools;
24extern crate text_unit; 24extern crate text_unit;
25extern crate unicode_xid; 25extern crate unicode_xid;
26extern crate drop_bomb; 26extern crate drop_bomb;
27extern crate parking_lot;
27 28
28pub mod algo; 29pub mod algo;
29pub mod ast; 30pub mod ast;
diff --git a/src/yellow/red.rs b/src/yellow/red.rs
index c3d6c5f4f..e124fc76e 100644
--- a/src/yellow/red.rs
+++ b/src/yellow/red.rs
@@ -1,4 +1,5 @@
1use std::{ptr, sync::RwLock}; 1use std::ptr;
2use parking_lot::RwLock;
2use {yellow::GreenNode, TextUnit}; 3use {yellow::GreenNode, TextUnit};
3 4
4#[derive(Debug)] 5#[derive(Debug)]
@@ -66,20 +67,20 @@ impl RedNode {
66 if idx >= self.n_children() { 67 if idx >= self.n_children() {
67 return None; 68 return None;
68 } 69 }
69 match &self.children.read().unwrap()[idx] { 70 match &self.children.read()[idx] {
70 Some(child) => return Some(child.into()), 71 Some(child) => return Some(child.into()),
71 None => (), 72 None => (),
72 } 73 }
73 let mut children = self.children.write().unwrap(); 74 let green_children = self.green.children();
75 let start_offset = self.start_offset()
76 + green_children[..idx]
77 .iter()
78 .map(|x| x.text_len())
79 .sum::<TextUnit>();
80 let child =
81 RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx);
82 let mut children = self.children.write();
74 if children[idx].is_none() { 83 if children[idx].is_none() {
75 let green_children = self.green.children();
76 let start_offset = self.start_offset()
77 + green_children[..idx]
78 .iter()
79 .map(|x| x.text_len())
80 .sum::<TextUnit>();
81 let child =
82 RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx);
83 children[idx] = Some(child) 84 children[idx] = Some(child)
84 } 85 }
85 Some(children[idx].as_ref().unwrap().into()) 86 Some(children[idx].as_ref().unwrap().into())