aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/yellow/green.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/green.rs
parent363f466627db373fab23d1df94b7382223b8675a (diff)
Avoid materializing strings
Diffstat (limited to 'crates/libsyntax2/src/yellow/green.rs')
-rw-r--r--crates/libsyntax2/src/yellow/green.rs16
1 files changed, 4 insertions, 12 deletions
diff --git a/crates/libsyntax2/src/yellow/green.rs b/crates/libsyntax2/src/yellow/green.rs
index 700f2704f..59aefb0de 100644
--- a/crates/libsyntax2/src/yellow/green.rs
+++ b/crates/libsyntax2/src/yellow/green.rs
@@ -43,21 +43,13 @@ impl GreenNode {
43 } 43 }
44 } 44 }
45 45
46 pub fn text(&self) -> String { 46 pub fn leaf_text(&self) -> Option<SmolStr> {
47 let mut buff = String::new(); 47 self.leaf_text_ref().map(Clone::clone)
48 go(self, &mut buff);
49 return buff;
50 fn go(node: &GreenNode, buff: &mut String) {
51 match node {
52 GreenNode::Leaf { text, .. } => buff.push_str(text.as_str()),
53 GreenNode::Branch(b) => b.children().iter().for_each(|child| go(child, buff)),
54 }
55 }
56 } 48 }
57 49
58 pub fn leaf_text(&self) -> Option<SmolStr> { 50 pub fn leaf_text_ref(&self) -> Option<&SmolStr> {
59 match self { 51 match self {
60 GreenNode::Leaf { text, .. } => Some(text.clone()), 52 GreenNode::Leaf { text, .. } => Some(text),
61 GreenNode::Branch(_) => None, 53 GreenNode::Branch(_) => None,
62 } 54 }
63 } 55 }