Skip to content

Commit 9470de6

Browse files
committed
[clang-doc] Reduce duplicate code with template
Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D142564
1 parent 6772966 commit 9470de6

File tree

1 file changed

+6
-41
lines changed

1 file changed

+6
-41
lines changed

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

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,16 @@ int getChildIndexIfExists(std::vector<T> &Children, T &ChildToMerge) {
5454
return -1;
5555
}
5656

57-
void reduceChildren(std::vector<Reference> &Children,
58-
std::vector<Reference> &&ChildrenToMerge) {
59-
for (auto &ChildToMerge : ChildrenToMerge) {
60-
int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
61-
if (mergeIdx == -1) {
62-
Children.push_back(std::move(ChildToMerge));
63-
continue;
64-
}
65-
Children[mergeIdx].merge(std::move(ChildToMerge));
66-
}
67-
}
68-
69-
void reduceChildren(std::vector<FunctionInfo> &Children,
70-
std::vector<FunctionInfo> &&ChildrenToMerge) {
71-
for (auto &ChildToMerge : ChildrenToMerge) {
72-
int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
73-
if (mergeIdx == -1) {
74-
Children.push_back(std::move(ChildToMerge));
75-
continue;
76-
}
77-
Children[mergeIdx].merge(std::move(ChildToMerge));
78-
}
79-
}
80-
81-
void reduceChildren(std::vector<EnumInfo> &Children,
82-
std::vector<EnumInfo> &&ChildrenToMerge) {
83-
for (auto &ChildToMerge : ChildrenToMerge) {
84-
int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
85-
if (mergeIdx == -1) {
86-
Children.push_back(std::move(ChildToMerge));
87-
continue;
88-
}
89-
Children[mergeIdx].merge(std::move(ChildToMerge));
90-
}
91-
}
92-
93-
void reduceChildren(std::vector<TypedefInfo> &Children,
94-
std::vector<TypedefInfo> &&ChildrenToMerge) {
57+
template <typename T>
58+
void reduceChildren(std::vector<T> &Children,
59+
std::vector<T> &&ChildrenToMerge) {
9560
for (auto &ChildToMerge : ChildrenToMerge) {
96-
int mergeIdx = getChildIndexIfExists(Children, ChildToMerge);
97-
if (mergeIdx == -1) {
61+
int MergeIdx = getChildIndexIfExists(Children, ChildToMerge);
62+
if (MergeIdx == -1) {
9863
Children.push_back(std::move(ChildToMerge));
9964
continue;
10065
}
101-
Children[mergeIdx].merge(std::move(ChildToMerge));
66+
Children[MergeIdx].merge(std::move(ChildToMerge));
10267
}
10368
}
10469

0 commit comments

Comments
 (0)