forked from OSchip/llvm-project
[Coverage] Clarify ownership of a MemoryBuffer in the reader (NFC)
Pass a `MemoryBuffer &` to BinaryCoverageReader::create() instead of a `std::unique_ptr<MemoryBuffer> &`. This makes it easier to reason about the ownership of the buffer at a glance. llvm-svn: 273326
This commit is contained in:
parent
310d3b975f
commit
7a7f5348a7
|
@ -181,8 +181,7 @@ private:
|
|||
|
||||
public:
|
||||
static Expected<std::unique_ptr<BinaryCoverageReader>>
|
||||
create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
|
||||
StringRef Arch);
|
||||
create(MemoryBuffer &ObjectBuffer, StringRef Arch);
|
||||
|
||||
Error readNextRecord(CoverageMappingRecord &Record) override;
|
||||
};
|
||||
|
|
|
@ -236,11 +236,13 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
|
|||
Expected<std::unique_ptr<CoverageMapping>>
|
||||
CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,
|
||||
StringRef Arch) {
|
||||
auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
|
||||
if (std::error_code EC = CounterMappingBuff.getError())
|
||||
auto CounterMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
|
||||
if (std::error_code EC = CounterMappingBufOrErr.getError())
|
||||
return errorCodeToError(EC);
|
||||
std::unique_ptr<MemoryBuffer> ObjectBuffer =
|
||||
std::move(CounterMappingBufOrErr.get());
|
||||
auto CoverageReaderOrErr =
|
||||
BinaryCoverageReader::create(CounterMappingBuff.get(), Arch);
|
||||
BinaryCoverageReader::create(*ObjectBuffer.get(), Arch);
|
||||
if (Error E = CoverageReaderOrErr.takeError())
|
||||
return std::move(E);
|
||||
auto CoverageReader = std::move(CoverageReaderOrErr.get());
|
||||
|
|
|
@ -641,8 +641,7 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
|
|||
}
|
||||
|
||||
Expected<std::unique_ptr<BinaryCoverageReader>>
|
||||
BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
|
||||
StringRef Arch) {
|
||||
BinaryCoverageReader::create(MemoryBuffer &ObjectBuffer, StringRef Arch) {
|
||||
std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader());
|
||||
|
||||
StringRef Coverage;
|
||||
|
@ -650,12 +649,12 @@ BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
|
|||
support::endianness Endian;
|
||||
Error E;
|
||||
consumeError(std::move(E));
|
||||
if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))
|
||||
if (ObjectBuffer.getBuffer().startswith(TestingFormatMagic))
|
||||
// This is a special format used for testing.
|
||||
E = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,
|
||||
E = loadTestingFormat(ObjectBuffer.getBuffer(), Reader->ProfileNames,
|
||||
Coverage, BytesInAddress, Endian);
|
||||
else
|
||||
E = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,
|
||||
E = loadBinaryFormat(ObjectBuffer.getMemBufferRef(), Reader->ProfileNames,
|
||||
Coverage, BytesInAddress, Endian, Arch);
|
||||
if (E)
|
||||
return std::move(E);
|
||||
|
|
Loading…
Reference in New Issue