[PATCH] D87468: [Support] Add GlobPattern::isTrivialMatchAll()
Andrew Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 07:48:43 PDT 2020
andrewng updated this revision to Diff 291217.
andrewng edited the summary of this revision.
andrewng added a comment.
Updated to address review comments and suggestions.
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,28 @@
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());
+ Expected<GlobPattern> Pat2 = GlobPattern::create("a*");
+ EXPECT_TRUE((bool)Pat2);
+ EXPECT_FALSE(Pat2->isTrivialMatchAll());
+ Expected<GlobPattern> Pat3 = GlobPattern::create("*a");
+ EXPECT_TRUE((bool)Pat3);
+ EXPECT_FALSE(Pat3->isTrivialMatchAll());
+ Expected<GlobPattern> Pat4 = GlobPattern::create("**");
+ EXPECT_TRUE((bool)Pat4);
+ EXPECT_FALSE(Pat4->isTrivialMatchAll());
+ Expected<GlobPattern> Pat5 = GlobPattern::create("?*");
+ EXPECT_TRUE((bool)Pat5);
+ EXPECT_FALSE(Pat5->isTrivialMatchAll());
+ Expected<GlobPattern> Pat6 = GlobPattern::create("*?");
+ EXPECT_TRUE((bool)Pat6);
+ EXPECT_FALSE(Pat6->isTrivialMatchAll());
+ Expected<GlobPattern> Pat7 = GlobPattern::create("\\*");
+ EXPECT_TRUE((bool)Pat7);
+ EXPECT_FALSE(Pat7->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.291217.patch
Type: text/x-patch
Size: 1937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200911/37cca691/attachment.bin>
More information about the llvm-commits
mailing list