Author: Paul Kirth
Date: 2026-04-10T17:58:25Z
New Revision: 86c307d96698b8e49eb912e06e796567c3df7daf

URL: 
https://github.com/llvm/llvm-project/commit/86c307d96698b8e49eb912e06e796567c3df7daf
DIFF: 
https://github.com/llvm/llvm-project/commit/86c307d96698b8e49eb912e06e796567c3df7daf.diff

LOG: [clang-doc] Consolidate merging logic (#190051)

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.

Added: 
    

Modified: 
    clang-tools-extra/clang-doc/Representation.cpp

Removed: 
    


################################################################################
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);


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to