[llvm-branch-commits] [clang-tools-extra] [clang-doc] Consolidate merging logic (PR #190051)
Paul Kirth via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Apr 3 16:15:47 PDT 2026
https://github.com/ilovepi updated https://github.com/llvm/llvm-project/pull/190051
>From 2463196182f60308a24ca35d812c012cbd2b462d Mon Sep 17 00:00:00 2001
From: Paul Kirth <paulkirth at google.com>
Date: Tue, 24 Mar 2026 18:01:08 +0000
Subject: [PATCH] [clang-doc] Consolidate merging logic
As we migrate things in the arena, this logic may get more complex.
Factoring it out now, will give clear extension points to make this
easier to manage.
---
.../clang-doc/Representation.cpp | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp
index 38dfa90453499..42f85c39655dd 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -146,6 +146,14 @@ static void reduceChildren(OwningVec<T> &Children,
}
}
+template <typename Container>
+static void mergeUnkeyed(Container &Target, Container &&Source) {
+ for (auto &Item : Source) {
+ if (llvm::none_of(Target, [&](const auto &E) { return E == Item; }))
+ Target.push_back(std::move(Item));
+ }
+}
+
// Dispatch function.
llvm::Expected<OwnedPtr<Info>> mergeInfos(OwningPtrArray<Info> &Values) {
if (Values.empty() || !Values[0])
@@ -292,11 +300,7 @@ void Info::mergeBase(Info &&Other) {
if (Namespace.empty())
Namespace = std::move(Other.Namespace);
// Unconditionally extend the description, since each decl may have a comment.
- std::move(Other.Description.begin(), Other.Description.end(),
- std::back_inserter(Description));
- llvm::sort(Description);
- auto Last = llvm::unique(Description);
- Description.erase(Last, Description.end());
+ mergeUnkeyed(Description, std::move(Other.Description));
if (ParentUSR == EmptySID)
ParentUSR = Other.ParentUSR;
if (DocumentationFileName.empty())
@@ -312,10 +316,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
if (!DefLoc)
DefLoc = std::move(Other.DefLoc);
// Unconditionally extend the list of locations, since we want all of them.
- std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc));
- llvm::sort(Loc);
- auto *Last = llvm::unique(Loc);
- Loc.erase(Last, Loc.end());
+ mergeUnkeyed(Loc, std::move(Other.Loc));
mergeBase(std::move(Other));
if (MangledName.empty())
MangledName = std::move(Other.MangledName);
More information about the llvm-branch-commits
mailing list