Skip to content

Commit b98ac06

Browse files
authored
[NFC][clang] Don't sort sections of SpecialCaseList (#162166)
Sorting was introduced in #112517. But it's not needed after #140127. `SpecialCaseList` stores sections in a vector now, to preserve declaration order. And don't remove default section, just skip it. Probably faster, but unlikely makes a difference.
1 parent 7e5bb1e commit b98ac06

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

clang/lib/Basic/Diagnostic.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -537,33 +537,16 @@ WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
537537
}
538538

539539
void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
540-
// Drop the default section introduced by special case list, we only support
541-
// exact diagnostic group names.
542-
// FIXME: We should make this configurable in the parser instead.
543-
// FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
544-
// sec.SectionStr == "*"; });
545-
llvm::erase_if(Sections, [](Section &sec) { return sec.SectionStr == "*"; });
546-
// Make sure we iterate sections by their line numbers.
547-
std::vector<std::pair<unsigned, const Section *>> LineAndSectionEntry;
548-
LineAndSectionEntry.reserve(Sections.size());
549-
for (const auto &Entry : Sections) {
550-
StringRef DiagName = Entry.SectionStr;
551-
// Each section has a matcher with that section's name, attached to that
552-
// line.
553-
const auto &DiagSectionMatcher = Entry.SectionMatcher;
554-
unsigned DiagLine = 0;
555-
for (const auto &Glob : DiagSectionMatcher->Globs)
556-
if (Glob->Name == DiagName) {
557-
DiagLine = Glob->LineNo;
558-
break;
559-
}
560-
LineAndSectionEntry.emplace_back(DiagLine, &Entry);
561-
}
562-
llvm::sort(LineAndSectionEntry);
563540
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
564-
for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
541+
for (const auto &SectionEntry : Sections) {
542+
StringRef DiagGroup = SectionEntry.SectionStr;
543+
if (DiagGroup == "*") {
544+
// Drop the default section introduced by special case list, we only
545+
// support exact diagnostic group names.
546+
// FIXME: We should make this configurable in the parser instead.
547+
continue;
548+
}
565549
SmallVector<diag::kind> GroupDiags;
566-
StringRef DiagGroup = SectionEntry->SectionStr;
567550
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
568551
WarningFlavor, DiagGroup, GroupDiags)) {
569552
StringRef Suggestion =
@@ -576,7 +559,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
576559
for (diag::kind Diag : GroupDiags)
577560
// We're intentionally overwriting any previous mappings here to make sure
578561
// latest one takes precedence.
579-
DiagToSection[Diag] = SectionEntry;
562+
DiagToSection[Diag] = &SectionEntry;
580563
}
581564
}
582565

0 commit comments

Comments
 (0)