Author: Rahul Joshi Date: 2024-11-13T07:08:58-08:00 New Revision: 4f1fe6d5f1607133883d116ef0c14582fbde7ada
URL: https://github.com/llvm/llvm-project/commit/4f1fe6d5f1607133883d116ef0c14582fbde7ada DIFF: https://github.com/llvm/llvm-project/commit/4f1fe6d5f1607133883d116ef0c14582fbde7ada.diff LOG: [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 <k...@google.com> Added: Modified: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp Removed: ################################################################################ diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp index 662c99fd47de3a..04c56e3a346e09 100644 --- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp +++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp @@ -1791,33 +1791,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