[cfe-commits] r39308 - in /cfe/cfe/trunk: AST/ASTContext.cpp include/clang/AST/Decl.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:42:51 PDT 2007
Author: sabre
Date: Wed Jul 11 11:42:51 2007
New Revision: 39308
URL: http://llvm.org/viewvc/llvm-project?rev=39308&view=rev
Log:
Use a cache in TypedefDecl to make ASTContext::getTypedefType trivial.
This speeds up parsing carbon.h from 16.0s to 11.3s, reducing slow
lookups from 63K to 32K.
Modified:
cfe/cfe/trunk/AST/ASTContext.cpp
cfe/cfe/trunk/include/clang/AST/Decl.h
Modified: cfe/cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/ASTContext.cpp?rev=39308&r1=39307&r2=39308&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/cfe/trunk/AST/ASTContext.cpp Wed Jul 11 11:42:51 2007
@@ -258,18 +258,11 @@
/// getTypedefType - Return the unique reference to the type for the
/// specified typename decl.
TypeRef ASTContext::getTypedefType(TypedefDecl *Decl) {
- // FIXME: This is obviously braindead!
- // Unique TypedefDecl, to guarantee there is only one TypedefType.
- ++NumSlowLookups;
- for (unsigned i = 0, e = Types.size(); i != e; ++i)
- if (TypedefType *Ty = dyn_cast<TypedefType>(Types[i]))
- if (Ty->getDecl() == Decl)
- return Types[i];
-
- // FIXME: does this lose qualifiers from the typedef??
+ if (Decl->TypeForDecl) return Decl->TypeForDecl;
+ // FIXME: does this lose qualifiers from the typedef??
Type *Canonical = Decl->getUnderlyingType().getTypePtr();
- Types.push_back(new TypedefType(Decl, Canonical));
+ Types.push_back(Decl->TypeForDecl = new TypedefType(Decl, Canonical));
return Types.back();
}
Modified: cfe/cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Decl.h?rev=39308&r1=39307&r2=39308&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Decl.h Wed Jul 11 11:42:51 2007
@@ -96,10 +96,15 @@
class TypedefDecl : public Decl {
/// UnderlyingType - This is the type the typedef is set to.
TypeRef UnderlyingType;
+
+ /// TypeForDecl - This indicates the Type object that represents this
+ /// TypedefDecl. It is a cache maintained by ASTContext::getTypedefType.
+ Type *TypeForDecl;
+ friend class ASTContext;
public:
// FIXME: Remove Declarator argument.
TypedefDecl(SourceLocation L, IdentifierInfo *Id, TypeRef T)
- : Decl(Typedef, L, Id), UnderlyingType(T) {}
+ : Decl(Typedef, L, Id), UnderlyingType(T), TypeForDecl(0) {}
TypeRef getUnderlyingType() const { return UnderlyingType; }
More information about the cfe-commits
mailing list