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 <rjo...@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"; } //===----------------------------------------------------------------------===// _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits