mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 17:07:26 +00:00
Merge #9367
9367: Document perf characteristic of to_node r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
e2ca2325f5
1 changed files with 9 additions and 0 deletions
|
@ -32,6 +32,15 @@ impl SyntaxNodePtr {
|
|||
SyntaxNodePtr { range: node.text_range(), kind: node.kind() }
|
||||
}
|
||||
|
||||
/// "Dereference" the pointer to get the node it points to.
|
||||
///
|
||||
/// Panics if node is not found, so make sure that `root` syntax tree is
|
||||
/// equivalent (is build from the same text) to the tree which was
|
||||
/// originally used to get this [`SyntaxNodePtr`].
|
||||
///
|
||||
/// The complexity is linear in the depth of the tree and logarithmic in
|
||||
/// tree width. As most trees are shallow, thinking about this as
|
||||
/// `O(log(N))` in the size of the tree is not too wrong!
|
||||
pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode {
|
||||
assert!(root.parent().is_none());
|
||||
successors(Some(root.clone()), |node| {
|
||||
|
|
Loading…
Reference in a new issue