-
Notifications
You must be signed in to change notification settings - Fork 14k
[SpecialCaseList] Iterate sections and matchers in reverse order #141697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
vitalybuka
wants to merge
4
commits into
main
from
users/vitalybuka/spr/specialcaselist-iterate-sections-and-matchers-in-reverse-order
Closed
[SpecialCaseList] Iterate sections and matchers in reverse order #141697
vitalybuka
wants to merge
4
commits into
main
from
users/vitalybuka/spr/specialcaselist-iterate-sections-and-matchers-in-reverse-order
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.6
@llvm/pr-subscribers-llvm-support Author: Vitaly Buka (vitalybuka) ChangesIssue #139128 needs to find the last one in the file. Full diff: https://github.com/llvm/llvm-project/pull/141697.diff 2 Files Affected:
diff --git a/llvm/lib/Support/SpecialCaseList.cpp b/llvm/lib/Support/SpecialCaseList.cpp
index 47ff3e24706a4..f9b5aafe88e98 100644
--- a/llvm/lib/Support/SpecialCaseList.cpp
+++ b/llvm/lib/Support/SpecialCaseList.cpp
@@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/SpecialCaseList.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/VirtualFileSystem.h"
@@ -66,10 +67,10 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, unsigned LineNumber,
}
unsigned SpecialCaseList::Matcher::match(StringRef Query) const {
- for (const auto &Glob : Globs)
+ for (const auto &Glob : reverse(Globs))
if (Glob->Pattern.match(Query))
return Glob->LineNo;
- for (const auto &[Regex, LineNumber] : RegExes)
+ for (const auto &[Regex, LineNumber] : reverse(RegExes))
if (Regex->match(Query))
return LineNumber;
return 0;
@@ -213,7 +214,7 @@ bool SpecialCaseList::inSection(StringRef Section, StringRef Prefix,
unsigned SpecialCaseList::inSectionBlame(StringRef Section, StringRef Prefix,
StringRef Query,
StringRef Category) const {
- for (const auto &S : Sections) {
+ for (const auto &S : reverse(Sections)) {
if (S.SectionMatcher->match(Section)) {
unsigned Blame = inSectionBlame(S.Entries, Prefix, Query, Category);
if (Blame)
diff --git a/llvm/unittests/Support/SpecialCaseListTest.cpp b/llvm/unittests/Support/SpecialCaseListTest.cpp
index eea185d142891..05e4e83090fd9 100644
--- a/llvm/unittests/Support/SpecialCaseListTest.cpp
+++ b/llvm/unittests/Support/SpecialCaseListTest.cpp
@@ -311,8 +311,7 @@ TEST_F(SpecialCaseListTest, LinesInSection) {
std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("fun:foo\n"
"fun:bar\n"
"fun:foo\n");
- // FIXME: Get the last one for #139128.
- EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo"));
+ EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo"));
EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar"));
}
@@ -322,8 +321,7 @@ TEST_F(SpecialCaseListTest, LinesCrossSection) {
"fun:foo\n"
"[sect1]\n"
"fun:bar\n");
- // FIXME: Get the last one for #139128.
- EXPECT_EQ(1u, SCL->inSectionBlame("sect1", "fun", "foo"));
- EXPECT_EQ(2u, SCL->inSectionBlame("sect1", "fun", "bar"));
+ EXPECT_EQ(3u, SCL->inSectionBlame("sect1", "fun", "foo"));
+ EXPECT_EQ(5u, SCL->inSectionBlame("sect1", "fun", "bar"));
}
}
|
vitalybuka
commented
May 28, 2025
@qinkunbao Please approve and merge if everything is OK here. |
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
May 28, 2025
… order Issue #139128 needs to find the last one in the file. Pull Request: llvm/llvm-project#141697
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Jun 3, 2025
Issue llvm#139128 needs to find the last one in the file. Pull Request: llvm#141697
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Extracted from #140529
Issue #139128 needs to find the last one in the file.
It's almost NFC, as the order of existing user of inSectionBlame is unimportant.