summaryrefslogtreecommitdiffstats
path: root/lib/Frontend/ChainedIncludesSource.cpp
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-07-07 11:06:51 +0000
committerAlp Toker <alp@nuanti.com>2014-07-07 11:06:51 +0000
commit1e2908f3ccb7f281abe429f28e57d3a167c15dd5 (patch)
treea130e75a359a356f8dcb37cf8f37582feaf36398 /lib/Frontend/ChainedIncludesSource.cpp
parent3bf4498407ce955210641f2bb23634901b48c5a7 (diff)
ChainedIncludesSource: avoid copying n*(n+1)/2 file contents into memory
Just reference the data instead with shallow MemoryBuffer instances. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212450 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ChainedIncludesSource.cpp')
-rw-r--r--lib/Frontend/ChainedIncludesSource.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/lib/Frontend/ChainedIncludesSource.cpp b/lib/Frontend/ChainedIncludesSource.cpp
index 01897cbf2a..387f67118e 100644
--- a/lib/Frontend/ChainedIncludesSource.cpp
+++ b/lib/Frontend/ChainedIncludesSource.cpp
@@ -126,17 +126,14 @@ ChainedIncludesSource::create(CompilerInstance &CI) {
} else {
assert(!serialBufs.empty());
SmallVector<llvm::MemoryBuffer *, 4> bufs;
- for (unsigned si = 0, se = serialBufs.size(); si != se; ++si) {
- bufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(
- StringRef(serialBufs[si]->getBufferStart(),
- serialBufs[si]->getBufferSize())));
- }
+ // TODO: Pass through the existing MemoryBuffer instances instead of
+ // allocating new ones.
+ for (auto *SB : serialBufs)
+ bufs.push_back(llvm::MemoryBuffer::getMemBuffer(SB->getBuffer()));
std::string pchName = includes[i-1];
llvm::raw_string_ostream os(pchName);
os << ".pch" << i-1;
- os.flush();
-
- serialBufNames.push_back(pchName);
+ serialBufNames.push_back(os.str());
IntrusiveRefCntPtr<ASTReader> Reader;
Reader = createASTReader(*Clang, pchName, bufs, serialBufNames,
@@ -151,11 +148,8 @@ ChainedIncludesSource::create(CompilerInstance &CI) {
return nullptr;
ParseAST(Clang->getSema());
- OS.flush();
Clang->getDiagnosticClient().EndSourceFile();
- serialBufs.push_back(
- llvm::MemoryBuffer::getMemBufferCopy(StringRef(serialAST.data(),
- serialAST.size())));
+ serialBufs.push_back(llvm::MemoryBuffer::getMemBufferCopy(OS.str()));
source->CIs.push_back(Clang.release());
}