[cfe-commits] r95543 - in /cfe/trunk: include/clang/AST/ASTImporter.h lib/AST/ASTImporter.cpp
Douglas Gregor
dgregor at apple.com
Mon Feb 8 07:18:59 PST 2010
Author: dgregor
Date: Mon Feb 8 09:18:58 2010
New Revision: 95543
URL: http://llvm.org/viewvc/llvm-project?rev=95543&view=rev
Log:
Cache imported types
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp
Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=95543&r1=95542&r2=95543&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Mon Feb 8 09:18:58 2010
@@ -17,6 +17,7 @@
#include "clang/AST/Type.h"
#include "clang/AST/DeclarationName.h"
#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMap.h"
namespace clang {
class ASTContext;
@@ -38,7 +39,11 @@
/// \brief The diagnostics object that we should use to emit diagnostics
/// within the context we're importing to and from.
Diagnostic &ToDiags, &FromDiags;
-
+
+ /// \brief Mapping from the already-imported types in the "from" context
+ /// to the corresponding types in the "to" context.
+ llvm::DenseMap<Type *, Type *> ImportedTypes;
+
public:
ASTImporter(ASTContext &ToContext, Diagnostic &ToDiags,
ASTContext &FromContext, Diagnostic &FromDiags);
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=95543&r1=95542&r2=95543&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Feb 8 09:18:58 2010
@@ -434,13 +434,21 @@
if (FromT.isNull())
return QualType();
- // FIXME: Cache type mappings?
+ // Check whether we've already imported this type.
+ llvm::DenseMap<Type *, Type *>::iterator Pos
+ = ImportedTypes.find(FromT.getTypePtr());
+ if (Pos != ImportedTypes.end())
+ return ToContext.getQualifiedType(Pos->second, FromT.getQualifiers());
+ // Import the type
ASTNodeImporter Importer(*this);
QualType ToT = Importer.Visit(FromT.getTypePtr());
if (ToT.isNull())
return ToT;
+ // Record the imported type.
+ ImportedTypes[FromT.getTypePtr()] = ToT.getTypePtr();
+
return ToContext.getQualifiedType(ToT, FromT.getQualifiers());
}
More information about the cfe-commits
mailing list