From: Vedant Kumar Date: Fri, 17 Jun 2016 21:31:03 +0000 (+0000) Subject: [Coverage] Get rid of an input/output parameter (NFC) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49f93f75af722f6224d588d697d40f537a05c956;p=llvm [Coverage] Get rid of an input/output parameter (NFC) readFunctionRecords is used to iterate through the entries of the coverage mapping section. Instead of expecting the function to update the iterator through a `const char *&` parameter, just return the updated iterator. This will help us experiment with zlib-compressing coverage mapping data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273052 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/lib/ProfileData/Coverage/CoverageMappingReader.cpp index c4d41b999b8..1a4b4f59084 100644 --- a/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -350,11 +350,15 @@ static Expected isCoverageMappingDummy(uint64_t Hash, StringRef Mapping) { namespace { struct CovMapFuncRecordReader { - // The interface to read coverage mapping function records for - // a module. \p Buf is a reference to the buffer pointer pointing - // to the \c CovHeader of coverage mapping data associated with - // the module. - virtual Error readFunctionRecords(const char *&Buf, const char *End) = 0; + // The interface to read coverage mapping function records for a module. + // + // \p Buf points to the buffer containing the \c CovHeader of the coverage + // mapping data associated with the module. + // + // Returns a pointer to the next \c CovHeader if it exists, or a pointer + // greater than \p End if not. + virtual Expected readFunctionRecords(const char *Buf, + const char *End) = 0; virtual ~CovMapFuncRecordReader() {} template static Expected> @@ -430,7 +434,8 @@ public: : ProfileNames(P), Filenames(F), Records(R) {} ~VersionedCovMapFuncRecordReader() override {} - Error readFunctionRecords(const char *&Buf, const char *End) override { + Expected readFunctionRecords(const char *Buf, + const char *End) override { using namespace support; if (Buf + sizeof(CovMapHeader) > End) return make_error(coveragemap_error::malformed); @@ -452,7 +457,7 @@ public: size_t FilenamesBegin = Filenames.size(); RawCoverageFilenamesReader Reader(StringRef(Buf, FilenamesSize), Filenames); if (auto Err = Reader.read()) - return Err; + return std::move(Err); Buf += FilenamesSize; // We'll read the coverage mapping records in the loop below. @@ -479,10 +484,10 @@ public: if (Error Err = insertFunctionRecordIfNeeded(CFR, Mapping, FilenamesBegin)) - return Err; + return std::move(Err); CFR++; } - return Error::success(); + return Buf; } }; } // end anonymous namespace @@ -526,8 +531,10 @@ static Error readCoverageMappingData( return E; auto Reader = std::move(ReaderExpected.get()); for (const char *Buf = Data.data(), *End = Buf + Data.size(); Buf < End;) { - if (Error E = Reader->readFunctionRecords(Buf, End)) + auto NextHeaderOrErr = Reader->readFunctionRecords(Buf, End); + if (auto E = NextHeaderOrErr.takeError()) return E; + Buf = NextHeaderOrErr.get(); } return Error::success(); }