[clang-tidy] Remove static StringSet in favor of binary search.

The number of strings is so small that performance doesn't matter and adding
the thread safe static initialization and destruction overhead is just not
worth it. No functional change intended.

llvm-svn: 235192
This commit is contained in:
Benjamin Kramer 2015-04-17 13:52:08 +00:00
parent a4ff7b2713
commit 73d2749a18
2 changed files with 29 additions and 37 deletions

View File

@ -11,35 +11,31 @@
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
using namespace clang::ast_matchers;
namespace {
bool isContainer(llvm::StringRef ClassName) {
static const llvm::StringSet<> ContainerNames = [] {
llvm::StringSet<> RetVal;
RetVal.insert("std::vector");
RetVal.insert("std::list");
RetVal.insert("std::array");
RetVal.insert("std::deque");
RetVal.insert("std::forward_list");
RetVal.insert("std::set");
RetVal.insert("std::map");
RetVal.insert("std::multiset");
RetVal.insert("std::multimap");
RetVal.insert("std::unordered_set");
RetVal.insert("std::unordered_map");
RetVal.insert("std::unordered_multiset");
RetVal.insert("std::unordered_multimap");
RetVal.insert("std::stack");
RetVal.insert("std::queue");
RetVal.insert("std::priority_queue");
return RetVal;
}();
return ContainerNames.find(ClassName) != ContainerNames.end();
static bool isContainer(llvm::StringRef ClassName) {
static const char *ContainerNames[] = {
"std::array",
"std::deque",
"std::forward_list",
"std::list",
"std::map",
"std::multimap",
"std::multiset",
"std::priority_queue",
"std::queue",
"std::set",
"std::stack",
"std::unordered_map",
"std::unordered_multimap",
"std::unordered_multiset",
"std::unordered_set",
"std::vector"
};
return std::binary_search(std::begin(ContainerNames),
std::end(ContainerNames), ClassName);
}
} // namespace
namespace clang {
namespace ast_matchers {

View File

@ -12,22 +12,18 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
using namespace clang::ast_matchers;
namespace {
bool isShrinkableContainer(llvm::StringRef ClassName) {
static const llvm::StringSet<> Shrinkables = [] {
llvm::StringSet<> RetVal;
RetVal.insert("std::deque");
RetVal.insert("std::basic_string");
RetVal.insert("std::vector");
return RetVal;
}();
return Shrinkables.find(ClassName) != Shrinkables.end();
static bool isShrinkableContainer(llvm::StringRef ClassName) {
static const char *Shrinkables[] = {
"std::basic_string",
"std::deque",
"std::vector"
};
return std::binary_search(std::begin(Shrinkables), std::end(Shrinkables),
ClassName);
}
} // namespace
namespace clang {
namespace ast_matchers {