[PATCH] D87468: [Support] Add GlobPattern::isTrivialMatchAll()
Andrew Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 02:27:48 PDT 2020
This revision was automatically updated to reflect the committed changes.
andrewng marked an inline comment as done.
Closed by commit rG6040e2a6d97d: [Support] Add GlobPattern::isTrivialMatchAll() (authored by andrewng).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D87468/new/
https://reviews.llvm.org/D87468
Files:
llvm/include/llvm/Support/GlobPattern.h
llvm/unittests/Support/GlobPatternTest.cpp
Index: llvm/unittests/Support/GlobPatternTest.cpp
===================================================================
--- llvm/unittests/Support/GlobPatternTest.cpp
+++ llvm/unittests/Support/GlobPatternTest.cpp
@@ -133,4 +133,17 @@
EXPECT_TRUE((bool)Pat2);
EXPECT_TRUE(Pat2->match("\xFF"));
}
+
+TEST_F(GlobPatternTest, IsTrivialMatchAll) {
+ Expected<GlobPattern> Pat1 = GlobPattern::create("*");
+ EXPECT_TRUE((bool)Pat1);
+ EXPECT_TRUE(Pat1->isTrivialMatchAll());
+
+ const char *NegativeCases[] = {"a*", "*a", "?*", "*?", "**", "\\*"};
+ for (auto *P : NegativeCases) {
+ Expected<GlobPattern> Pat2 = GlobPattern::create(P);
+ EXPECT_TRUE((bool)Pat2);
+ EXPECT_FALSE(Pat2->isTrivialMatchAll());
+ }
+}
}
Index: llvm/include/llvm/Support/GlobPattern.h
===================================================================
--- llvm/include/llvm/Support/GlobPattern.h
+++ llvm/include/llvm/Support/GlobPattern.h
@@ -31,6 +31,16 @@
static Expected<GlobPattern> create(StringRef Pat);
bool match(StringRef S) const;
+ // Returns true for glob pattern "*". Can be used to avoid expensive
+ // preparation/acquisition of the input for match().
+ bool isTrivialMatchAll() const {
+ if (Prefix && Prefix->empty()) {
+ assert(!Suffix);
+ return true;
+ }
+ return false;
+ }
+
private:
bool matchOne(ArrayRef<BitVector> Pat, StringRef S) const;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87468.292155.patch
Type: text/x-patch
Size: 1398 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200916/c90faee2/attachment.bin>
More information about the llvm-commits
mailing list