Skip to content

Commit 3d5f48d

Browse files
committed
Refactor GlobList from an ad-hoc linked list to a vector
Summary: I think it makes method implementations more obvious. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66788 llvm-svn: 370039
1 parent 0c26921 commit 3d5f48d

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

clang-tools-extra/clang-tidy/GlobList.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,20 @@ static llvm::Regex ConsumeGlob(StringRef &GlobList) {
4242
return llvm::Regex(RegexText);
4343
}
4444

45-
GlobList::GlobList(StringRef Globs)
46-
: Positive(!ConsumeNegativeIndicator(Globs)), Regex(ConsumeGlob(Globs)),
47-
NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {}
48-
49-
bool GlobList::contains(StringRef S, bool Contains) {
50-
if (Regex.match(S))
51-
Contains = Positive;
45+
GlobList::GlobList(StringRef Globs) {
46+
do {
47+
GlobListItem Item;
48+
Item.IsPositive = !ConsumeNegativeIndicator(Globs);
49+
Item.Regex = ConsumeGlob(Globs);
50+
Items.push_back(std::move(Item));
51+
} while (!Globs.empty());
52+
}
5253

53-
if (NextGlob)
54-
Contains = NextGlob->contains(S, Contains);
54+
bool GlobList::contains(StringRef S) {
55+
bool Contains = false;
56+
for (const GlobListItem &Item : Items) {
57+
if (Item.Regex.match(S))
58+
Contains = Item.IsPositive;
59+
}
5560
return Contains;
5661
}

clang-tools-extra/clang-tidy/GlobList.h

+17-11
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,36 @@
1212
#include "clang/Basic/LLVM.h"
1313
#include "llvm/ADT/StringRef.h"
1414
#include "llvm/Support/Regex.h"
15-
#include <memory>
15+
#include <vector>
1616

1717
namespace clang {
1818
namespace tidy {
1919

20-
/// Read-only set of strings represented as a list of positive and
21-
/// negative globs. Positive globs add all matched strings to the set, negative
22-
/// globs remove them in the order of appearance in the list.
20+
/// Read-only set of strings represented as a list of positive and negative
21+
/// globs.
22+
///
23+
/// Positive globs add all matched strings to the set, negative globs remove
24+
/// them in the order of appearance in the list.
2325
class GlobList {
2426
public:
25-
/// \p GlobList is a comma-separated list of globs (only '*'
26-
/// metacharacter is supported) with optional '-' prefix to denote exclusion.
27+
/// \p Globs is a comma-separated list of globs (only the '*' metacharacter is
28+
/// supported) with an optional '-' prefix to denote exclusion.
29+
///
30+
/// An empty \p Globs string is interpreted as one glob that matches an empty
31+
/// string.
2732
GlobList(StringRef Globs);
2833

2934
/// Returns \c true if the pattern matches \p S. The result is the last
3035
/// matching glob's Positive flag.
31-
bool contains(StringRef S) { return contains(S, false); }
36+
bool contains(StringRef S);
3237

3338
private:
34-
bool contains(StringRef S, bool Contains);
3539

36-
bool Positive;
37-
llvm::Regex Regex;
38-
std::unique_ptr<GlobList> NextGlob;
40+
struct GlobListItem {
41+
bool IsPositive;
42+
mutable llvm::Regex Regex;
43+
};
44+
std::vector<GlobListItem> Items;
3945
};
4046

4147
} // end namespace tidy

0 commit comments

Comments
 (0)