]> granicus.if.org Git - clang/commitdiff
Replace the StringSwitch in AttributeList::getKind() with a
authorDouglas Gregor <dgregor@apple.com>
Wed, 2 May 2012 17:33:51 +0000 (17:33 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 2 May 2012 17:33:51 +0000 (17:33 +0000)
TableGen-generated StringMatcher, for a 1.2% speedup in -fparse-only
time in <rdar://problem/11004361>. Thanks to Benjamin for pointing me
at StringMatcher!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156003 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AttributeList.cpp
utils/TableGen/ClangAttrEmitter.cpp

index cbd2ba4194190f58385472700fdc7ff4f650fef7..101e0384fa77bc19050ee9700f2b5c44642b4aa2 100644 (file)
@@ -97,6 +97,8 @@ AttributePool::createIntegerAttribute(ASTContext &C, IdentifierInfo *Name,
   return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0);
 }
 
+#include "clang/Sema/AttrParsedAttrKinds.inc"
+
 AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
   StringRef AttrName = Name->getName();
 
@@ -105,7 +107,5 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
       AttrName.size() >= 4)
     AttrName = AttrName.substr(2, AttrName.size() - 4);
 
-  return llvm::StringSwitch<AttributeList::Kind>(AttrName)
-    #include "clang/Sema/AttrParsedAttrKinds.inc"
-    .Default(UnknownAttribute);
+  return ::getAttrKind(AttrName);
 }
index 112d9a5f23ffd642fa73d75cf035ee352a8e36dd..4177660e26b9c8f3cae116827b82820a90145ce0 100644 (file)
@@ -14,6 +14,7 @@
 #include "ClangAttrEmitter.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
 #include <algorithm>
 #include <cctype>
 #include <set>
@@ -1085,9 +1086,11 @@ void ClangAttrParsedAttrListEmitter::run(raw_ostream &OS) {
 
 void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) {
   OS << "// This file is generated by TableGen. Do not edit.\n\n";
-
+  OS << "\n";
+  
   std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
 
+  std::vector<StringMatcher::StringPair> Matches;
   for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end();
        I != E; ++I) {
     Record &Attr = **I;
@@ -1107,12 +1110,23 @@ void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) {
         Spelling = NormalizeAttrSpelling(Spelling);
 
         if (SemaHandler)
-          OS << ".Case(\"" << Spelling << "\", " << "AT_" << AttrName << ")\n";
+          Matches.push_back(
+            StringMatcher::StringPair(Spelling,
+                                      std::string("return AttributeList::AT_") +
+                                      AttrName.str() + ";"));
         else
-          OS << ".Case(\"" << Spelling << "\", IgnoredAttribute)\n";
+          Matches.push_back(
+            StringMatcher::StringPair(
+              Spelling,
+              std::string("return AttributeList::IgnoredAttribute;")));
       }
     }
   }
+  
+  OS << "static AttributeList::Kind getAttrKind(StringRef Name) {\n";
+  StringMatcher("Name", Matches, OS).Emit();
+  OS << "return AttributeList::UnknownAttribute;\n"
+     << "}\n";
 }