From 2999b77f1d1aec8b715b75d6724df6e905b73969 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 22 Feb 2013 18:29:39 +0000 Subject: [PATCH] Replace some typically large vectors with SmallVector. This may seem counter-intuitive but the POD-like optimization helps when the vectors grow into multimegabyte buffers. SmallVector calls realloc which knows how to twiddle virtual memory bits and avoids large copies. llvm-svn: 175906 --- clang/include/clang/AST/ASTContext.h | 8 ++++---- clang/include/clang/Basic/SourceManager.h | 4 ++-- clang/lib/Basic/SourceManager.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index b483535..7c02699 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -75,7 +75,7 @@ namespace clang { class ASTContext : public RefCountedBase { ASTContext &this_() { return *this; } - mutable std::vector Types; + mutable SmallVector Types; mutable llvm::FoldingSet ExtQualNodes; mutable llvm::FoldingSet ComplexTypes; mutable llvm::FoldingSet PointerTypes; @@ -748,7 +748,7 @@ public: ASTMutationListener *getASTMutationListener() const { return Listener; } void PrintStats() const; - const std::vector& getTypes() const { return Types; } + const SmallVectorImpl& getTypes() const { return Types; } /// \brief Retrieve the declaration for the 128-bit signed integer type. TypedefDecl *getInt128Decl() const; @@ -1908,8 +1908,8 @@ public: // Type Iterators. //===--------------------------------------------------------------------===// - typedef std::vector::iterator type_iterator; - typedef std::vector::const_iterator const_type_iterator; + typedef SmallVectorImpl::iterator type_iterator; + typedef SmallVectorImpl::const_iterator const_type_iterator; type_iterator types_begin() { return Types.begin(); } type_iterator types_end() { return Types.end(); } diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index b4a8591..d7c71a7 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -588,13 +588,13 @@ class SourceManager : public RefCountedBase { /// /// Positive FileIDs are indexes into this table. Entry 0 indicates an invalid /// expansion. - std::vector LocalSLocEntryTable; + SmallVector LocalSLocEntryTable; /// \brief The table of SLocEntries that are loaded from other modules. /// /// Negative FileIDs are indexes into this table. To get from ID to an index, /// use (-ID - 2). - mutable std::vector LoadedSLocEntryTable; + mutable SmallVector LoadedSLocEntryTable; /// \brief The starting offset of the next local SLocEntry. /// diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 901d3a6..c5d275a 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -721,7 +721,7 @@ FileID SourceManager::getFileIDLocal(unsigned SLocOffset) const { // See if this is near the file point - worst case we start scanning from the // most newly created FileID. - std::vector::const_iterator I; + const SrcMgr::SLocEntry *I; if (LastFileIDLookup.ID < 0 || LocalSLocEntryTable[LastFileIDLookup.ID].getOffset() < SLocOffset) { -- 2.7.4