[PATCH] D42189: [clang-format] Replace unordered_set with an array

Krasimir Georgiev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 17 12:03:23 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL322749: [clang-format] Replace unordered_set with an array (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42189

Files:
  cfe/trunk/lib/Format/Format.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===================================================================
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -41,25 +41,14 @@
 #include <algorithm>
 #include <memory>
 #include <string>
-#include <unordered_set>
 
 #define DEBUG_TYPE "format-formatter"
 
 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 @@
 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 @@
               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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42189.130245.patch
Type: text/x-patch
Size: 2036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180117/20deaeb4/attachment.bin>


More information about the llvm-commits mailing list