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:
|
public:
|
||||||
static Expected<std::unique_ptr<BinaryCoverageReader>>
|
static Expected<std::unique_ptr<BinaryCoverageReader>>
|
||||||
create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
|
create(MemoryBuffer &ObjectBuffer, StringRef Arch);
|
||||||
StringRef Arch);
|
|
||||||
|
|
||||||
Error readNextRecord(CoverageMappingRecord &Record) override;
|
Error readNextRecord(CoverageMappingRecord &Record) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -236,11 +236,13 @@ CoverageMapping::load(CoverageMappingReader &CoverageReader,
|
||||||
Expected<std::unique_ptr<CoverageMapping>>
|
Expected<std::unique_ptr<CoverageMapping>>
|
||||||
CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,
|
CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,
|
||||||
StringRef Arch) {
|
StringRef Arch) {
|
||||||
auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
|
auto CounterMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
|
||||||
if (std::error_code EC = CounterMappingBuff.getError())
|
if (std::error_code EC = CounterMappingBufOrErr.getError())
|
||||||
return errorCodeToError(EC);
|
return errorCodeToError(EC);
|
||||||
|
std::unique_ptr<MemoryBuffer> ObjectBuffer =
|
||||||
|
std::move(CounterMappingBufOrErr.get());
|
||||||
auto CoverageReaderOrErr =
|
auto CoverageReaderOrErr =
|
||||||
BinaryCoverageReader::create(CounterMappingBuff.get(), Arch);
|
BinaryCoverageReader::create(*ObjectBuffer.get(), Arch);
|
||||||
if (Error E = CoverageReaderOrErr.takeError())
|
if (Error E = CoverageReaderOrErr.takeError())
|
||||||
return std::move(E);
|
return std::move(E);
|
||||||
auto CoverageReader = std::move(CoverageReaderOrErr.get());
|
auto CoverageReader = std::move(CoverageReaderOrErr.get());
|
||||||
|
|
|
@ -641,8 +641,7 @@ static Error loadBinaryFormat(MemoryBufferRef ObjectBuffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
Expected<std::unique_ptr<BinaryCoverageReader>>
|
Expected<std::unique_ptr<BinaryCoverageReader>>
|
||||||
BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
|
BinaryCoverageReader::create(MemoryBuffer &ObjectBuffer, StringRef Arch) {
|
||||||
StringRef Arch) {
|
|
||||||
std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader());
|
std::unique_ptr<BinaryCoverageReader> Reader(new BinaryCoverageReader());
|
||||||
|
|
||||||
StringRef Coverage;
|
StringRef Coverage;
|
||||||
|
@ -650,12 +649,12 @@ BinaryCoverageReader::create(std::unique_ptr<MemoryBuffer> &ObjectBuffer,
|
||||||
support::endianness Endian;
|
support::endianness Endian;
|
||||||
Error E;
|
Error E;
|
||||||
consumeError(std::move(E));
|
consumeError(std::move(E));
|
||||||
if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))
|
if (ObjectBuffer.getBuffer().startswith(TestingFormatMagic))
|
||||||
// This is a special format used for testing.
|
// This is a special format used for testing.
|
||||||
E = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,
|
E = loadTestingFormat(ObjectBuffer.getBuffer(), Reader->ProfileNames,
|
||||||
Coverage, BytesInAddress, Endian);
|
Coverage, BytesInAddress, Endian);
|
||||||
else
|
else
|
||||||
E = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,
|
E = loadBinaryFormat(ObjectBuffer.getMemBufferRef(), Reader->ProfileNames,
|
||||||
Coverage, BytesInAddress, Endian, Arch);
|
Coverage, BytesInAddress, Endian, Arch);
|
||||||
if (E)
|
if (E)
|
||||||
return std::move(E);
|
return std::move(E);
|
||||||
|
|
Loading…
Reference in New Issue