[clang] [NFC][lang][TableGen] Simplify `EmitClangDiagsIndexName` (PR #115962)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 12 20:09:58 PST 2024


================
@@ -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();
----------------
kazutakahirata wrote:

nit: `LHS` and `RHS` seem to be about 50 times as popular as `Lhs` and `Rhs` in our codebase, respectively.  I understand that are you are updating the existing code here, but could we take the opportunity and rename the variables?

```suggestion
  sort(Diags, [](const Record *LHS, const Record *RHS) {
    return LHS->getName() < RHS->getName();
```

https://github.com/llvm/llvm-project/pull/115962


More information about the cfe-commits mailing list