diff options
Diffstat (limited to 'crates/libsyntax2/src/yellow/green.rs')
-rw-r--r-- | crates/libsyntax2/src/yellow/green.rs | 16 |
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 | } |