aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax')
-rw-r--r--crates/syntax/Cargo.toml1
-rw-r--r--crates/syntax/src/algo.rs13
2 files changed, 14 insertions, 0 deletions
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index 1fe907753..ce62babc3 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -28,6 +28,7 @@ stdx = { path = "../stdx", version = "0.0.0" }
28text_edit = { path = "../text_edit", version = "0.0.0" } 28text_edit = { path = "../text_edit", version = "0.0.0" }
29parser = { path = "../parser", version = "0.0.0" } 29parser = { path = "../parser", version = "0.0.0" }
30test_utils = { path = "../test_utils", version = "0.0.0" } 30test_utils = { path = "../test_utils", version = "0.0.0" }
31profile = { path = "../profile", version = "0.0.0" }
31 32
32[dev-dependencies] 33[dev-dependencies]
33walkdir = "2.3.1" 34walkdir = "2.3.1"
diff --git a/crates/syntax/src/algo.rs b/crates/syntax/src/algo.rs
index 320c430c9..ee89d9867 100644
--- a/crates/syntax/src/algo.rs
+++ b/crates/syntax/src/algo.rs
@@ -127,6 +127,8 @@ pub struct TreeDiff {
127 127
128impl TreeDiff { 128impl TreeDiff {
129 pub fn into_text_edit(&self, builder: &mut TextEditBuilder) { 129 pub fn into_text_edit(&self, builder: &mut TextEditBuilder) {
130 let _p = profile::span("into_text_edit");
131
130 for (anchor, to) in self.insertions.iter() { 132 for (anchor, to) in self.insertions.iter() {
131 let offset = match anchor { 133 let offset = match anchor {
132 TreeDiffInsertPos::After(it) => it.text_range().end(), 134 TreeDiffInsertPos::After(it) => it.text_range().end(),
@@ -154,6 +156,8 @@ impl TreeDiff {
154/// 156///
155/// This function tries to find a fine-grained diff. 157/// This function tries to find a fine-grained diff.
156pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff { 158pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
159 let _p = profile::span("diff");
160
157 let mut diff = TreeDiff { 161 let mut diff = TreeDiff {
158 replacements: FxHashMap::default(), 162 replacements: FxHashMap::default(),
159 insertions: FxIndexMap::default(), 163 insertions: FxIndexMap::default(),
@@ -467,6 +471,8 @@ impl<'a> SyntaxRewriter<'a> {
467 } 471 }
468 472
469 pub fn rewrite(&self, node: &SyntaxNode) -> SyntaxNode { 473 pub fn rewrite(&self, node: &SyntaxNode) -> SyntaxNode {
474 let _p = profile::span("rewrite");
475
470 if self.f.is_none() && self.replacements.is_empty() && self.insertions.is_empty() { 476 if self.f.is_none() && self.replacements.is_empty() && self.insertions.is_empty() {
471 return node.clone(); 477 return node.clone();
472 } 478 }
@@ -483,6 +489,7 @@ impl<'a> SyntaxRewriter<'a> {
483 /// 489 ///
484 /// Returns `None` when there are no replacements. 490 /// Returns `None` when there are no replacements.
485 pub fn rewrite_root(&self) -> Option<SyntaxNode> { 491 pub fn rewrite_root(&self) -> Option<SyntaxNode> {
492 let _p = profile::span("rewrite_root");
486 fn element_to_node_or_parent(element: &SyntaxElement) -> SyntaxNode { 493 fn element_to_node_or_parent(element: &SyntaxElement) -> SyntaxNode {
487 match element { 494 match element {
488 SyntaxElement::Node(it) => it.clone(), 495 SyntaxElement::Node(it) => it.clone(),
@@ -517,6 +524,8 @@ impl<'a> SyntaxRewriter<'a> {
517 } 524 }
518 525
519 fn rewrite_children(&self, node: &SyntaxNode) -> SyntaxNode { 526 fn rewrite_children(&self, node: &SyntaxNode) -> SyntaxNode {
527 let _p = profile::span("rewrite_children");
528
520 // FIXME: this could be made much faster. 529 // FIXME: this could be made much faster.
521 let mut new_children = Vec::new(); 530 let mut new_children = Vec::new();
522 if let Some(elements) = self.insertions(&InsertPos::FirstChildOf(node.clone())) { 531 if let Some(elements) = self.insertions(&InsertPos::FirstChildOf(node.clone())) {
@@ -533,6 +542,8 @@ impl<'a> SyntaxRewriter<'a> {
533 acc: &mut Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>, 542 acc: &mut Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
534 element: &SyntaxElement, 543 element: &SyntaxElement,
535 ) { 544 ) {
545 let _p = profile::span("rewrite_self");
546
536 if let Some(replacement) = self.replacement(&element) { 547 if let Some(replacement) = self.replacement(&element) {
537 match replacement { 548 match replacement {
538 Replacement::Single(element) => acc.push(element_to_green(element)), 549 Replacement::Single(element) => acc.push(element_to_green(element)),
@@ -588,6 +599,8 @@ fn with_children(
588 parent: &SyntaxNode, 599 parent: &SyntaxNode,
589 new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>, 600 new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>,
590) -> SyntaxNode { 601) -> SyntaxNode {
602 let _p = profile::span("with_children");
603
591 let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>(); 604 let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>();
592 let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children); 605 let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children);
593 let new_root_node = parent.replace_with(new_node); 606 let new_root_node = parent.replace_with(new_node);