Skip to content

Commit

Permalink
[clang-format] Replace unordered_set with an array
Browse files Browse the repository at this point in the history
Summary: This replaces an unordered_set from r322690 with an array and binary search.

Reviewers: bkramer, benhamilton

Reviewed By: bkramer, benhamilton

Subscribers: jolesiak, benhamilton, klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D42189

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322749 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
krasimirgg committed Jan 17, 2018
1 parent 3d90a2c commit b6a88f3
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <algorithm>
#include <memory>
#include <string>
#include <unordered_set>

#define DEBUG_TYPE "format-formatter"

Expand All @@ -50,16 +49,6 @@ using clang::format::FormatStyle;
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)

namespace std {
// Allow using StringRef in std::unordered_set.
template <> struct hash<llvm::StringRef> {
public:
size_t operator()(const llvm::StringRef &s) const {
return llvm::hash_value(s);
}
};
} // namespace std

namespace llvm {
namespace yaml {
template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
Expand Down Expand Up @@ -1432,7 +1421,8 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
private:
static bool guessIsObjC(const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
const AdditionalKeywords &Keywords) {
static const std::unordered_set<StringRef> FoundationIdentifiers = {
// Keep this array sorted, since we are binary searching over it.
static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
"CGFloat",
"NSAffineTransform",
"NSArray",
Expand Down Expand Up @@ -1490,8 +1480,9 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
tok::l_brace))) ||
(FormatTok->Tok.isAnyIdentifier() &&
FoundationIdentifiers.find(FormatTok->TokenText) !=
FoundationIdentifiers.end()) ||
std::binary_search(std::begin(FoundationIdentifiers),
std::end(FoundationIdentifiers),
FormatTok->TokenText)) ||
FormatTok->is(TT_ObjCStringLiteral) ||
FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,
Expand Down

0 comments on commit b6a88f3

Please sign in to comment.