[Lldb-commits] [lldb] e2d4761 - [lldb][NFC] Replace ClangASTImporter's use of map/set with SmallPtrSet and DenseMap

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Sun Dec 15 23:29:56 PST 2019


Author: Raphael Isemann
Date: 2019-12-16T08:29:14+01:00
New Revision: e2d47614a81d0805a869e614ffff1512e0136da9

URL: https://github.com/llvm/llvm-project/commit/e2d47614a81d0805a869e614ffff1512e0136da9
DIFF: https://github.com/llvm/llvm-project/commit/e2d47614a81d0805a869e614ffff1512e0136da9.diff

LOG: [lldb][NFC] Replace ClangASTImporter's use of map/set with SmallPtrSet and DenseMap

We have several pointer->pointer mappings in the ClangASTImporter implemented using
STL data structures. This moves these variables to the appropriate LLVM data structures
that are intended for mapping pointers.

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/ClangASTImporter.h
    lldb/source/Symbol/ClangASTImporter.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/ClangASTImporter.h b/lldb/include/lldb/Symbol/ClangASTImporter.h
index a67b698ef490..098091f7167f 100644
--- a/lldb/include/lldb/Symbol/ClangASTImporter.h
+++ b/lldb/include/lldb/Symbol/ClangASTImporter.h
@@ -182,7 +182,7 @@ class ClangASTImporter {
     clang::Decl *decl;
   };
 
-  typedef std::map<const clang::Decl *, DeclOrigin> OriginMap;
+  typedef llvm::DenseMap<const clang::Decl *, DeclOrigin> OriginMap;
 
   /// Listener interface used by the ASTImporterDelegate to inform other code
   /// about decls that have been imported the first time.
@@ -262,7 +262,7 @@ class ClangASTImporter {
     /// ASTContext. Used by the CxxModuleHandler to mark declarations that
     /// were created from the 'std' C++ module to prevent that the Importer
     /// tries to sync them with the broken equivalent in the debug info AST.
-    std::set<clang::Decl *> m_decls_to_ignore;
+    llvm::SmallPtrSet<clang::Decl *, 16> m_decls_to_ignore;
     ClangASTImporter &m_master;
     clang::ASTContext *m_source_ctx;
     CxxModuleHandler *m_std_handler = nullptr;
@@ -271,8 +271,8 @@ class ClangASTImporter {
   };
 
   typedef std::shared_ptr<ASTImporterDelegate> ImporterDelegateSP;
-  typedef std::map<clang::ASTContext *, ImporterDelegateSP> DelegateMap;
-  typedef std::map<const clang::NamespaceDecl *, NamespaceMapSP>
+  typedef llvm::DenseMap<clang::ASTContext *, ImporterDelegateSP> DelegateMap;
+  typedef llvm::DenseMap<const clang::NamespaceDecl *, NamespaceMapSP>
       NamespaceMetaMap;
 
   struct ASTContextMetadata {
@@ -289,7 +289,7 @@ class ClangASTImporter {
   };
 
   typedef std::shared_ptr<ASTContextMetadata> ASTContextMetadataSP;
-  typedef std::map<const clang::ASTContext *, ASTContextMetadataSP>
+  typedef llvm::DenseMap<const clang::ASTContext *, ASTContextMetadataSP>
       ContextMetadataMap;
 
   ContextMetadataMap m_metadata_map;

diff  --git a/lldb/source/Symbol/ClangASTImporter.cpp b/lldb/source/Symbol/ClangASTImporter.cpp
index 8b1c6c8f815e..80c5c4a6f345 100644
--- a/lldb/source/Symbol/ClangASTImporter.cpp
+++ b/lldb/source/Symbol/ClangASTImporter.cpp
@@ -121,7 +121,7 @@ class DeclContextOverride {
     clang::DeclContext *lexical_decl_context;
   };
 
-  std::map<clang::Decl *, Backup> m_backups;
+  llvm::DenseMap<clang::Decl *, Backup> m_backups;
 
   void OverrideOne(clang::Decl *decl) {
     if (m_backups.find(decl) != m_backups.end()) {
@@ -228,10 +228,8 @@ namespace {
 /// imported while completing the original Decls).
 class CompleteTagDeclsScope : public ClangASTImporter::NewDeclListener {
   ClangASTImporter::ImporterDelegateSP m_delegate;
-  // FIXME: Investigate how many decls we usually have in these sets and
-  // see if we can use SmallPtrSet instead here.
-  std::set<NamedDecl *> m_decls_to_complete;
-  std::set<NamedDecl *> m_decls_already_completed;
+  llvm::SmallPtrSet<NamedDecl *, 32> m_decls_to_complete;
+  llvm::SmallPtrSet<NamedDecl *, 32> m_decls_already_completed;
   clang::ASTContext *m_dst_ctx;
   clang::ASTContext *m_src_ctx;
   ClangASTImporter &importer;


        


More information about the lldb-commits mailing list