finer concurrency
This commit is contained in:
parent
1954df6336
commit
7264c3294b
@ -12,6 +12,7 @@ unicode-xid = "0.1.0"
|
||||
text_unit = "0.1.2"
|
||||
itertools = "0.7.5"
|
||||
drop_bomb = "0.1.4"
|
||||
parking_lot = "0.6.0"
|
||||
|
||||
[dev-dependencies]
|
||||
testutils = { path = "./tests/testutils" }
|
||||
|
@ -24,6 +24,7 @@
|
||||
extern crate text_unit;
|
||||
extern crate unicode_xid;
|
||||
extern crate drop_bomb;
|
||||
extern crate parking_lot;
|
||||
|
||||
pub mod algo;
|
||||
pub mod ast;
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::{ptr, sync::RwLock};
|
||||
use std::ptr;
|
||||
use parking_lot::RwLock;
|
||||
use {yellow::GreenNode, TextUnit};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -66,20 +67,20 @@ pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> {
|
||||
if idx >= self.n_children() {
|
||||
return None;
|
||||
}
|
||||
match &self.children.read().unwrap()[idx] {
|
||||
match &self.children.read()[idx] {
|
||||
Some(child) => return Some(child.into()),
|
||||
None => (),
|
||||
}
|
||||
let mut children = self.children.write().unwrap();
|
||||
let green_children = self.green.children();
|
||||
let start_offset = self.start_offset()
|
||||
+ green_children[..idx]
|
||||
.iter()
|
||||
.map(|x| x.text_len())
|
||||
.sum::<TextUnit>();
|
||||
let child =
|
||||
RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx);
|
||||
let mut children = self.children.write();
|
||||
if children[idx].is_none() {
|
||||
let green_children = self.green.children();
|
||||
let start_offset = self.start_offset()
|
||||
+ green_children[..idx]
|
||||
.iter()
|
||||
.map(|x| x.text_len())
|
||||
.sum::<TextUnit>();
|
||||
let child =
|
||||
RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx);
|
||||
children[idx] = Some(child)
|
||||
}
|
||||
Some(children[idx].as_ref().unwrap().into())
|
||||
|
Loading…
Reference in New Issue
Block a user