diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-22 09:46:01 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-22 09:46:01 +0100 |
commit | e2ca2325f5f61284a4c924114a78cd263b4921cb (patch) | |
tree | 8b383d80f81ebf2598fa04652f73921b159c9773 /crates/syntax/src | |
parent | 37dc2dfada170c28237f7bd20dec6476a420df32 (diff) | |
parent | e611c6758cb1a7f36b0f7aa91be327870f4f0592 (diff) |
Merge #9367
9367: Document perf characteristic of to_node r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax/src')
-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 32aa69979..282470bae 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| { |