[dsymutil] Refactor BinaryHolder internals. NFC

Call a helper that resets all the internal state of the BinaryHolder
when we change the underlying memory buffer. Makes a followup patch
a tiny bit smaller.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243094 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Frederic Riss 2015-07-24 06:40:59 +00:00
parent 26be214232
commit e10885312d
2 changed files with 15 additions and 4 deletions

View File

@ -18,6 +18,14 @@
namespace llvm {
namespace dsymutil {
void BinaryHolder::changeBackingMemoryBuffer(
std::unique_ptr<MemoryBuffer> &&Buf) {
CurrentArchive.reset();
CurrentObjectFile.reset();
CurrentMemoryBuffer = std::move(Buf);
}
ErrorOr<MemoryBufferRef>
BinaryHolder::GetMemoryBufferForFile(StringRef Filename,
sys::TimeValue Timestamp) {
@ -44,10 +52,9 @@ BinaryHolder::GetMemoryBufferForFile(StringRef Filename,
if (auto Err = ErrOrFile.getError())
return Err;
changeBackingMemoryBuffer(std::move(*ErrOrFile));
if (Verbose)
outs() << "\tloaded file.\n";
CurrentArchive.reset();
CurrentMemoryBuffer = std::move(ErrOrFile.get());
return CurrentMemoryBuffer->getMemBufferRef();
}
@ -93,12 +100,14 @@ BinaryHolder::MapArchiveAndGetMemberBuffer(StringRef Filename,
if (Verbose)
outs() << "\topened new archive '" << ArchiveFilename << "'\n";
auto ErrOrArchive = object::Archive::create((*ErrOrBuff)->getMemBufferRef());
changeBackingMemoryBuffer(std::move(*ErrOrBuff));
auto ErrOrArchive =
object::Archive::create(CurrentMemoryBuffer->getMemBufferRef());
if (auto Err = ErrOrArchive.getError())
return Err;
CurrentArchive = std::move(*ErrOrArchive);
CurrentMemoryBuffer = std::move(*ErrOrBuff);
return GetArchiveMemberBuffer(Filename, Timestamp);
}

View File

@ -67,6 +67,8 @@ class BinaryHolder {
ErrorOr<MemoryBufferRef> GetMemoryBufferForFile(StringRef Filename,
sys::TimeValue Timestamp);
void changeBackingMemoryBuffer(std::unique_ptr<MemoryBuffer> &&MemBuf);
public:
BinaryHolder(bool Verbose) : Verbose(Verbose) {}