[clang] [NFC][lang][TableGen] Simplify `EmitClangDiagsIndexName` (PR #115962)
Rahul Joshi via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 12 15:54:38 PST 2024
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/115962
Simplify `EmitClangDiagsIndexName` to directly sort records instead of creating an array of `RecordIndexElement` containing record name and sorting it.
>From 07c74bee58d1a56978b1cba00755cc3ca14cb71f Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 12 Nov 2024 15:51:54 -0800
Subject: [PATCH] [NFC][lang][TableGen] Simplify `EmitClangDiagsIndexName`
Simplify `EmitClangDiagsIndexName` to directly sort records instead of
creating an array of `RecordIndexElement` containing record name and
sorting it.
---
.../TableGen/ClangDiagnosticsEmitter.cpp | 26 ++++---------------
1 file changed, 5 insertions(+), 21 deletions(-)
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index b7fd59090cd995..6d42e927a3d630 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1786,33 +1786,17 @@ void clang::EmitClangDiagGroups(const RecordKeeper &Records, raw_ostream &OS) {
// Diagnostic name index generation
//===----------------------------------------------------------------------===//
-namespace {
-struct RecordIndexElement
-{
- RecordIndexElement() {}
- explicit RecordIndexElement(Record const &R)
- : Name(std::string(R.getName())) {}
-
- std::string Name;
-};
-} // end anonymous namespace.
-
void clang::EmitClangDiagsIndexName(const RecordKeeper &Records,
raw_ostream &OS) {
- ArrayRef<const Record *> Diags =
+ std::vector<const Record *> Diags =
Records.getAllDerivedDefinitions("Diagnostic");
- std::vector<RecordIndexElement> Index;
- Index.reserve(Diags.size());
- for (const Record *R : Diags)
- Index.push_back(RecordIndexElement(*R));
-
- sort(Index, [](const RecordIndexElement &Lhs, const RecordIndexElement &Rhs) {
- return Lhs.Name < Rhs.Name;
+ sort(Diags, [](const Record *Lhs, const Record *Rhs) {
+ return Lhs->getName() < Rhs->getName();
});
- for (const auto &Elem : Index)
- OS << "DIAG_NAME_INDEX(" << Elem.Name << ")\n";
+ for (const Record *Elem : Diags)
+ OS << "DIAG_NAME_INDEX(" << Elem->getName() << ")\n";
}
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list