Author: Paul Kirth
Date: 2023-01-26T18:05:31Z
New Revision: 9470de65bb33a18842d64ab2ab777902613ee014

URL: 
https://github.com/llvm/llvm-project/commit/9470de65bb33a18842d64ab2ab777902613ee014
DIFF: 
https://github.com/llvm/llvm-project/commit/9470de65bb33a18842d64ab2ab777902613ee014.diff

LOG: [clang-doc] Reduce duplicate code with template

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D142564

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 31bb07d04b35d..3d078d575a127 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -54,51 +54,16 @@ int getChildIndexIfExists(std::vector<T> &Children, T 
&ChildToMerge) {
   return -1;
 }
 
-void reduceChildren(std::vector<Reference> &Children,
-                    std::vector<Reference> &&ChildrenToMerge) {
-  for (auto &ChildToMerge : ChildrenToMerge) {
-    int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-    if (mergeIdx == -1) {
-      Children.push_back(std::move(ChildToMerge));
-      continue;
-    }
-    Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector<FunctionInfo> &Children,
-                    std::vector<FunctionInfo> &&ChildrenToMerge) {
-  for (auto &ChildToMerge : ChildrenToMerge) {
-    int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-    if (mergeIdx == -1) {
-      Children.push_back(std::move(ChildToMerge));
-      continue;
-    }
-    Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector<EnumInfo> &Children,
-                    std::vector<EnumInfo> &&ChildrenToMerge) {
-  for (auto &ChildToMerge : ChildrenToMerge) {
-    int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-    if (mergeIdx == -1) {
-      Children.push_back(std::move(ChildToMerge));
-      continue;
-    }
-    Children[mergeIdx].merge(std::move(ChildToMerge));
-  }
-}
-
-void reduceChildren(std::vector<TypedefInfo> &Children,
-                    std::vector<TypedefInfo> &&ChildrenToMerge) {
+template <typename T>
+void reduceChildren(std::vector<T> &Children,
+                    std::vector<T> &&ChildrenToMerge) {
   for (auto &ChildToMerge : ChildrenToMerge) {
-    int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
-    if (mergeIdx == -1) {
+    int MergeIdx = getChildIndexIfExists(Children, ChildToMerge);
+    if (MergeIdx == -1) {
       Children.push_back(std::move(ChildToMerge));
       continue;
     }
-    Children[mergeIdx].merge(std::move(ChildToMerge));
+    Children[MergeIdx].merge(std::move(ChildToMerge));
   }
 }
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to