Skip to content

Commit 8e21678

Browse files
committedJan 17, 2018
[clang-format] Replace unordered_set with an array
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 llvm-svn: 322749
1 parent c9dc7b4 commit 8e21678

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed
 

‎clang/lib/Format/Format.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include <algorithm>
4242
#include <memory>
4343
#include <string>
44-
#include <unordered_set>
4544

4645
#define DEBUG_TYPE "format-formatter"
4746

@@ -50,16 +49,6 @@ using clang::format::FormatStyle;
5049
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
5150
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
5251

53-
namespace std {
54-
// Allow using StringRef in std::unordered_set.
55-
template <> struct hash<llvm::StringRef> {
56-
public:
57-
size_t operator()(const llvm::StringRef &s) const {
58-
return llvm::hash_value(s);
59-
}
60-
};
61-
} // namespace std
62-
6352
namespace llvm {
6453
namespace yaml {
6554
template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
@@ -1432,7 +1421,8 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
14321421
private:
14331422
static bool guessIsObjC(const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines,
14341423
const AdditionalKeywords &Keywords) {
1435-
static const std::unordered_set<StringRef> FoundationIdentifiers = {
1424+
// Keep this array sorted, since we are binary searching over it.
1425+
static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
14361426
"CGFloat",
14371427
"NSAffineTransform",
14381428
"NSArray",
@@ -1490,8 +1480,9 @@ class ObjCHeaderStyleGuesser : public TokenAnalyzer {
14901480
FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
14911481
tok::l_brace))) ||
14921482
(FormatTok->Tok.isAnyIdentifier() &&
1493-
FoundationIdentifiers.find(FormatTok->TokenText) !=
1494-
FoundationIdentifiers.end()) ||
1483+
std::binary_search(std::begin(FoundationIdentifiers),
1484+
std::end(FoundationIdentifiers),
1485+
FormatTok->TokenText)) ||
14951486
FormatTok->is(TT_ObjCStringLiteral) ||
14961487
FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
14971488
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,

0 commit comments

Comments
 (0)
Please sign in to comment.