for (char C : Glob) {
if (C == '*')
RegexText.push_back('.');
- else if (MetaChars.find(C) != StringRef::npos)
+ else if (MetaChars.contains(C))
RegexText.push_back('\\');
RegexText.push_back(C);
}
}
GlobList::GlobList(StringRef Globs) {
+ Items.reserve(Globs.count(',') + 1);
do {
GlobListItem Item;
Item.IsPositive = !ConsumeNegativeIndicator(Globs);
}
bool GlobList::contains(StringRef S) {
- bool Contains = false;
- for (const GlobListItem &Item : Items) {
+ // Iterating the container backwards as the last match determins if S is in
+ // the list.
+ for (const GlobListItem &Item : llvm::reverse(Items)) {
if (Item.Regex.match(S))
- Contains = Item.IsPositive;
+ return Item.IsPositive;
}
- return Contains;
+ return false;
}
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Regex.h"
-#include <vector>
namespace clang {
namespace tidy {
struct GlobListItem {
bool IsPositive;
- mutable llvm::Regex Regex;
+ llvm::Regex Regex;
};
- std::vector<GlobListItem> Items;
+ SmallVector<GlobListItem, 0> Items;
};
} // end namespace tidy