[llvm-branch-commits] [clang] Speed up diagnostic state file lookup (PR #241234)
Kazu Hirata via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 11 09:54:46 PST 2026
================
@@ -262,9 +262,16 @@ void DiagnosticsEngine::DiagStateMap::dump(SourceManager &SrcMgr,
CurDiagStateLoc.print(llvm::errs(), SrcMgr);
llvm::errs() << ": " << CurDiagState << "\n";
- for (auto &F : Files) {
+ SmallVector<std::pair<FileID, File *>, 16> SortedFiles;
+ for (auto &F : Files)
+ SortedFiles.emplace_back(F.first, F.second.get());
+ llvm::sort(SortedFiles, [](const auto &LHS, const auto &RHS) {
+ return LHS.first.getOpaqueValue() < RHS.first.getOpaqueValue();
+ });
----------------
kazutakahirata wrote:
May I suggest using a structured binding and `llvm::less_first()` here? Note that `FileID::operator<` already compares the underlying `ID` values directly.
```suggestion
for (const auto &[ID, FilePtr] : Files)
SortedFiles.emplace_back(ID, FilePtr.get());
llvm::sort(SortedFiles, llvm::less_first());
```
https://github.com/llvm/llvm-project/pull/241234
More information about the llvm-branch-commits
mailing list