aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/yellow/mod.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-28 12:06:30 +0100
committerAleksey Kladov <[email protected]>2018-08-28 12:06:30 +0100
commit7e74af32268f9b0783ca94107b0b10d52e4ebe5e (patch)
tree179d818c695a27ceee3f8193e219234854190f9a /crates/libsyntax2/src/yellow/mod.rs
parent363f466627db373fab23d1df94b7382223b8675a (diff)
Avoid materializing strings
Diffstat (limited to 'crates/libsyntax2/src/yellow/mod.rs')
-rw-r--r--crates/libsyntax2/src/yellow/mod.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/yellow/mod.rs b/crates/libsyntax2/src/yellow/mod.rs
index b94c794fe..82eda79d6 100644
--- a/crates/libsyntax2/src/yellow/mod.rs
+++ b/crates/libsyntax2/src/yellow/mod.rs
@@ -2,6 +2,7 @@ mod builder;
2mod green; 2mod green;
3mod red; 3mod red;
4mod syntax; 4mod syntax;
5mod syntax_text;
5 6
6use std::{ 7use std::{
7 sync::Arc, 8 sync::Arc,
@@ -12,6 +13,7 @@ pub(crate) use self::{
12 builder::GreenBuilder, 13 builder::GreenBuilder,
13 green::GreenNode, 14 green::GreenNode,
14 red::RedNode, 15 red::RedNode,
16 syntax_text::SyntaxText,
15}; 17};
16 18
17#[derive(Debug)] 19#[derive(Debug)]
@@ -32,6 +34,12 @@ pub struct OwnedRoot(Arc<SyntaxRoot>);
32#[derive(Clone, Copy, Debug)] 34#[derive(Clone, Copy, Debug)]
33pub struct RefRoot<'a>(&'a OwnedRoot); // TODO: shared_from_this instead of double indirection 35pub struct RefRoot<'a>(&'a OwnedRoot); // TODO: shared_from_this instead of double indirection
34 36
37impl<'a> RefRoot<'a> {
38 fn syntax_root(&self) -> &'a SyntaxRoot {
39 self.0.syntax_root()
40 }
41}
42
35impl TreeRoot for OwnedRoot { 43impl TreeRoot for OwnedRoot {
36 fn borrowed(&self) -> RefRoot { 44 fn borrowed(&self) -> RefRoot {
37 RefRoot(&self) 45 RefRoot(&self)
@@ -78,7 +86,7 @@ impl RedPtr {
78 RedPtr(red.into()) 86 RedPtr(red.into())
79 } 87 }
80 88
81 unsafe fn get<'a>(self, _root: &'a impl TreeRoot) -> &'a RedNode { 89 unsafe fn get<'a>(self, _root: &'a SyntaxRoot) -> &'a RedNode {
82 &*self.0.as_ptr() 90 &*self.0.as_ptr()
83 } 91 }
84} 92}