summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/Selection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/Selection.cpp')
-rw-r--r--clang-tools-extra/clangd/Selection.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/clang-tools-extra/clangd/Selection.cpp b/clang-tools-extra/clangd/Selection.cpp
index 9c2fb27a626..7e41de02758 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -358,13 +358,10 @@ SelectionTree::SelectionTree(ASTContext &AST, unsigned Offset)
const Node *SelectionTree::commonAncestor() const {
if (!Root)
return nullptr;
- for (const Node *Ancestor = Root;; Ancestor = Ancestor->Children.front()) {
- if (Ancestor->Selected || Ancestor->Children.size() > 1)
- return Ancestor;
- // The tree only contains ancestors of the interesting nodes.
- assert(!Ancestor->Children.empty() && "bad node in selection tree");
- }
- return nullptr;
+ const Node *Ancestor = Root;
+ while (Ancestor->Children.size() == 1 && !Ancestor->Selected)
+ Ancestor = Ancestor->Children.front();
+ return Ancestor;
}
} // namespace clangd
OpenPOWER on IntegriCloud