summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-01-17 20:01:02 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-01-17 20:01:02 +0000
commit8e21678d5b5c8b91a8d6ca9ba6a66e6cd5ba344f (patch)
treea7f0a3e7ce27017ceb1b4e78f333aa8894503a77 /clang/lib/Format
parentc9dc7b451b48be78681627a90339b4e7ee66fcb8 (diff)
downloadbcm5719-llvm-8e21678d5b5c8b91a8d6ca9ba6a66e6cd5ba344f.tar.gz
bcm5719-llvm-8e21678d5b5c8b91a8d6ca9ba6a66e6cd5ba344f.zip
[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
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/Format.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 896e055d870..3044b3a56e2 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -41,7 +41,6 @@
#include <algorithm>
#include <memory>
#include <string>
-#include <unordered_set>
#define DEBUG_TYPE "format-formatter"
@@ -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> {
@@ -1432,7 +1421,8 @@ public:
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",
@@ -1490,8 +1480,9 @@ private:
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,
OpenPOWER on IntegriCloud