[PATCH] D87468: [Support] Add GlobPattern::isTrivialMatchAll()
Andrew Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 07:06:56 PDT 2020
andrewng updated this revision to Diff 291904.
andrewng marked an inline comment as done.
andrewng added a comment.
Update for review comments.
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 (unsigned i = 0; i < array_lengthof(NegativeCases); ++i) {
+ Expected<GlobPattern> Pat2 = GlobPattern::create(NegativeCases[i]);
+ 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.291904.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200915/517c9240/attachment.bin>
More information about the llvm-commits
mailing list