Skip to content

Commit 4f1fe6d

Browse files
[NFC][lang][TableGen] Simplify EmitClangDiagsIndexName (#115962)
Simplify `EmitClangDiagsIndexName` to directly sort records instead of creating an array of `RecordIndexElement` containing record name and sorting it. --------- Co-authored-by: Kazu Hirata <[email protected]>
1 parent 46b2757 commit 4f1fe6d

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,33 +1791,17 @@ void clang::EmitClangDiagGroups(const RecordKeeper &Records, raw_ostream &OS) {
17911791
// Diagnostic name index generation
17921792
//===----------------------------------------------------------------------===//
17931793

1794-
namespace {
1795-
struct RecordIndexElement
1796-
{
1797-
RecordIndexElement() {}
1798-
explicit RecordIndexElement(Record const &R)
1799-
: Name(std::string(R.getName())) {}
1800-
1801-
std::string Name;
1802-
};
1803-
} // end anonymous namespace.
1804-
18051794
void clang::EmitClangDiagsIndexName(const RecordKeeper &Records,
18061795
raw_ostream &OS) {
1807-
ArrayRef<const Record *> Diags =
1796+
std::vector<const Record *> Diags =
18081797
Records.getAllDerivedDefinitions("Diagnostic");
18091798

1810-
std::vector<RecordIndexElement> Index;
1811-
Index.reserve(Diags.size());
1812-
for (const Record *R : Diags)
1813-
Index.push_back(RecordIndexElement(*R));
1814-
1815-
sort(Index, [](const RecordIndexElement &Lhs, const RecordIndexElement &Rhs) {
1816-
return Lhs.Name < Rhs.Name;
1799+
sort(Diags, [](const Record *LHS, const Record *RHS) {
1800+
return LHS->getName() < RHS->getName();
18171801
});
18181802

1819-
for (const auto &Elem : Index)
1820-
OS << "DIAG_NAME_INDEX(" << Elem.Name << ")\n";
1803+
for (const Record *Elem : Diags)
1804+
OS << "DIAG_NAME_INDEX(" << Elem->getName() << ")\n";
18211805
}
18221806

18231807
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)