diff options
author | Aleksey Kladov <[email protected]> | 2021-06-22 09:45:22 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-22 09:45:22 +0100 |
commit | e611c6758cb1a7f36b0f7aa91be327870f4f0592 (patch) | |
tree | dda47939ef2a207601831ab1b751310e58eb5a7d | |
parent | 56e61bdfea5454dec4408a4947e037bcd042c886 (diff) |
Document perf characteristic of to_node
-rw-r--r-- | crates/syntax/src/ptr.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs index 195d2251b..c077a04cb 100644 --- a/crates/syntax/src/ptr.rs +++ b/crates/syntax/src/ptr.rs | |||
@@ -32,6 +32,15 @@ impl SyntaxNodePtr { | |||
32 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } | 32 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } |
33 | } | 33 | } |
34 | 34 | ||
35 | /// "Dereference" the pointer to get the node it points to. | ||
36 | /// | ||
37 | /// Panics if node is not found, so make sure that `root` syntax tree is | ||
38 | /// equivalent (is build from the same text) to the tree which was | ||
39 | /// originally used to get this [`SyntaxNodePtr`]. | ||
40 | /// | ||
41 | /// The complexity is linear in the depth of the tree and logarithmic in | ||
42 | /// tree width. As most trees are shallow, thinking about this as | ||
43 | /// `O(log(N))` in the size of the tree is not too wrong! | ||
35 | pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { | 44 | pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { |
36 | assert!(root.parent().is_none()); | 45 | assert!(root.parent().is_none()); |
37 | successors(Some(root.clone()), |node| { | 46 | successors(Some(root.clone()), |node| { |