[PATCH] D142564: [clang-doc] Reduce duplicate code with template
Paul Kirth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 25 09:33:09 PST 2023
paulkirth created this revision.
Herald added a project: All.
paulkirth requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142564
Files:
clang-tools-extra/clang-doc/Representation.cpp
Index: clang-tools-extra/clang-doc/Representation.cpp
===================================================================
--- clang-tools-extra/clang-doc/Representation.cpp
+++ clang-tools-extra/clang-doc/Representation.cpp
@@ -54,51 +54,15 @@
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));
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142564.492155.patch
Type: text/x-patch
Size: 2142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230125/019c1c2a/attachment.bin>
More information about the cfe-commits
mailing list