aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Tooling/Syntax/BuildTree.cpp
diff options
context:
space:
mode:
authorEduardo Caldas <ecaldas@google.com>2020-10-27 15:14:03 +0000
committerEduardo Caldas <ecaldas@google.com>2020-11-05 09:33:53 +0000
commit23657d9cc33282208bdac074abccd73bd4d4f8be (patch)
treeeee8b552048a918e74c7e3fec6569d9a06d8ddeb /clang/lib/Tooling/Syntax/BuildTree.cpp
parentb715fa330dfaa379885c5184340c410a63be5987 (diff)
downloadllvm-23657d9cc33282208bdac074abccd73bd4d4f8be.zip
llvm-23657d9cc33282208bdac074abccd73bd4d4f8be.tar.gz
llvm-23657d9cc33282208bdac074abccd73bd4d4f8be.tar.bz2
[SyntaxTree] Add reverse links to syntax Nodes.
Rationale: Children of a syntax tree had forward links only, because there was no need for reverse links. This need appeared when we started mutating the syntax tree. On a forward list, to remove a target node in O(1) we need a pointer to the node before the target. If we don't have this "before" pointer, we have to find it, and that requires O(n). So in order to remove a syntax node from a tree, we would similarly need to find the node before to then remove. This is both not ergonomic nor does it have a good complexity. Differential Revision: https://reviews.llvm.org/D90240
Diffstat (limited to 'clang/lib/Tooling/Syntax/BuildTree.cpp')
-rw-r--r--clang/lib/Tooling/Syntax/BuildTree.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 1975905..6777782 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -636,12 +636,11 @@ private:
(EndChildren == Trees.end() || EndChildren->first == Tokens.end()) &&
"fold crosses boundaries of existing subtrees");
- // We need to go in reverse order, because we can only prepend.
- for (auto It = EndChildren; It != BeginChildren; --It) {
- auto *C = std::prev(It)->second;
+ for (auto It = BeginChildren; It != EndChildren; ++It) {
+ auto *C = It->second;
if (C->getRole() == NodeRole::Detached)
C->setRole(NodeRole::Unknown);
- Node->prependChildLowLevel(C);
+ Node->appendChildLowLevel(C);
}
// Mark that this node came from the AST and is backed by the source code.