From 18f5119559e0204eac4d62f1500bea26f51a8fd7 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 21 Oct 2025 16:05:03 -0700 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.6 [skip ci] --- llvm/include/llvm/Support/GlobPattern.h | 13 +++++++------ llvm/lib/Support/GlobPattern.cpp | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/Support/GlobPattern.h b/llvm/include/llvm/Support/GlobPattern.h index c1b44849b9794..09be8343a6ef2 100644 --- a/llvm/include/llvm/Support/GlobPattern.h +++ b/llvm/include/llvm/Support/GlobPattern.h @@ -63,21 +63,22 @@ class GlobPattern { // Returns true for glob pattern "*". Can be used to avoid expensive // preparation/acquisition of the input for match(). bool isTrivialMatchAll() const { - if (!Prefix.empty()) + if (PrefixSize) return false; - if (!Suffix.empty()) + if (SuffixSize) return false; if (SubGlobs.size() != 1) return false; return SubGlobs[0].getPat() == "*"; } - StringRef prefix() const { return Prefix; } - StringRef suffix() const { return Suffix; } + StringRef prefix() const { return Pattern.take_front(PrefixSize); } + StringRef suffix() const { return Pattern.take_back(SuffixSize); } private: - StringRef Prefix; - StringRef Suffix; + StringRef Pattern; + size_t PrefixSize = 0; + size_t SuffixSize = 0; struct SubGlobPattern { /// \param Pat the pattern to match against diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp index 0ecf47dc1d3d1..f56a8fcf4bf9d 100644 --- a/llvm/lib/Support/GlobPattern.cpp +++ b/llvm/lib/Support/GlobPattern.cpp @@ -135,21 +135,24 @@ parseBraceExpansions(StringRef S, std::optional MaxSubPatterns) { Expected GlobPattern::create(StringRef S, std::optional MaxSubPatterns) { GlobPattern Pat; + Pat.Pattern = S; // Store the prefix that does not contain any metacharacter. - size_t PrefixSize = S.find_first_of("?*[{\\"); - Pat.Prefix = S.substr(0, PrefixSize); - if (PrefixSize == std::string::npos) + Pat.PrefixSize = S.find_first_of("?*[{\\"); + if (Pat.PrefixSize == std::string::npos) { + Pat.PrefixSize = S.size(); return Pat; - S = S.substr(PrefixSize); + } + S = S.substr(Pat.PrefixSize); // Just in case we stop on unmatched opening brackets. size_t SuffixStart = S.find_last_of("?*[]{}\\"); assert(SuffixStart != std::string::npos); if (S[SuffixStart] == '\\') ++SuffixStart; - ++SuffixStart; - Pat.Suffix = S.substr(SuffixStart); + if (SuffixStart < S.size()) + ++SuffixStart; + Pat.SuffixSize = S.size() - SuffixStart; S = S.substr(0, SuffixStart); SmallVector SubPats; @@ -200,9 +203,9 @@ GlobPattern::SubGlobPattern::create(StringRef S) { } bool GlobPattern::match(StringRef S) const { - if (!S.consume_front(Prefix)) + if (!S.consume_front(prefix())) return false; - if (!S.consume_back(Suffix)) + if (!S.consume_back(suffix())) return false; if (SubGlobs.empty() && S.empty()) return true; From 986276ee56fb242c10cf648b43e4b91a1f815ce1 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 21 Oct 2025 16:06:20 -0700 Subject: [PATCH 2/2] rebase Created using spr 1.3.6 --- llvm/include/llvm/Support/GlobPattern.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/GlobPattern.h b/llvm/include/llvm/Support/GlobPattern.h index 230898edf1881..6ebf64565559b 100644 --- a/llvm/include/llvm/Support/GlobPattern.h +++ b/llvm/include/llvm/Support/GlobPattern.h @@ -72,7 +72,7 @@ class GlobPattern { return SubGlobs[0].getPat() == "*"; } - // The followind functions are just shortcuts for faster matching. They are + // The following functions are just shortcuts for faster matching. They are // conservative to simplify implementations. // Returns plain prefix of the pattern.