llvm.org GIT mirror llvm / 1037ef2
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273326 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
3 changed file(s) with 10 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
180180
181181 public:
182182 static Expected>
183 create(std::unique_ptr &ObjectBuffer,
184 StringRef Arch);
183 create(MemoryBuffer &ObjectBuffer, StringRef Arch);
185184
186185 Error readNextRecord(CoverageMappingRecord &Record) override;
187186 };
235235 Expected>
236236 CoverageMapping::load(StringRef ObjectFilename, StringRef ProfileFilename,
237237 StringRef Arch) {
238 auto CounterMappingBuff = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
239 if (std::error_code EC = CounterMappingBuff.getError())
238 auto CounterMappingBufOrErr = MemoryBuffer::getFileOrSTDIN(ObjectFilename);
239 if (std::error_code EC = CounterMappingBufOrErr.getError())
240240 return errorCodeToError(EC);
241 std::unique_ptr ObjectBuffer =
242 std::move(CounterMappingBufOrErr.get());
241243 auto CoverageReaderOrErr =
242 BinaryCoverageReader::create(CounterMappingBuff.get(), Arch);
244 BinaryCoverageReader::create(*ObjectBuffer.get(), Arch);
243245 if (Error E = CoverageReaderOrErr.takeError())
244246 return std::move(E);
245247 auto CoverageReader = std::move(CoverageReaderOrErr.get());
640640 }
641641
642642 Expected>
643 BinaryCoverageReader::create(std::unique_ptr &ObjectBuffer,
644 StringRef Arch) {
643 BinaryCoverageReader::create(MemoryBuffer &ObjectBuffer, StringRef Arch) {
645644 std::unique_ptr Reader(new BinaryCoverageReader());
646645
647646 StringRef Coverage;
649648 support::endianness Endian;
650649 Error E;
651650 consumeError(std::move(E));
652 if (ObjectBuffer->getBuffer().startswith(TestingFormatMagic))
651 if (ObjectBuffer.getBuffer().startswith(TestingFormatMagic))
653652 // This is a special format used for testing.
654 E = loadTestingFormat(ObjectBuffer->getBuffer(), Reader->ProfileNames,
653 E = loadTestingFormat(ObjectBuffer.getBuffer(), Reader->ProfileNames,
655654 Coverage, BytesInAddress, Endian);
656655 else
657 E = loadBinaryFormat(ObjectBuffer->getMemBufferRef(), Reader->ProfileNames,
656 E = loadBinaryFormat(ObjectBuffer.getMemBufferRef(), Reader->ProfileNames,
658657 Coverage, BytesInAddress, Endian, Arch);
659658 if (E)
660659 return std::move(E);