aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/lib.rs1
-rw-r--r--src/yellow/red.rs23
3 files changed, 14 insertions, 11 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 8af8f825b..c343ac57b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ unicode-xid = "0.1.0"
12text_unit = "0.1.2" 12text_unit = "0.1.2"
13itertools = "0.7.5" 13itertools = "0.7.5"
14drop_bomb = "0.1.4" 14drop_bomb = "0.1.4"
15parking_lot = "0.6.0"
15 16
16[dev-dependencies] 17[dev-dependencies]
17testutils = { path = "./tests/testutils" } 18testutils = { path = "./tests/testutils" }
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())