diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /include/llvm/Support/BinaryStreamArray.h | |
parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) |
Notes
Diffstat (limited to 'include/llvm/Support/BinaryStreamArray.h')
-rw-r--r-- | include/llvm/Support/BinaryStreamArray.h | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/include/llvm/Support/BinaryStreamArray.h b/include/llvm/Support/BinaryStreamArray.h index d1571cb37fc6..7c110fcb6a4b 100644 --- a/include/llvm/Support/BinaryStreamArray.h +++ b/include/llvm/Support/BinaryStreamArray.h @@ -96,21 +96,32 @@ public: explicit VarStreamArray(const Extractor &E) : E(E) {} - explicit VarStreamArray(BinaryStreamRef Stream) : Stream(Stream) {} + explicit VarStreamArray(BinaryStreamRef Stream, uint32_t Skew = 0) + : Stream(Stream), Skew(Skew) {} - VarStreamArray(BinaryStreamRef Stream, const Extractor &E) - : Stream(Stream), E(E) {} + VarStreamArray(BinaryStreamRef Stream, const Extractor &E, uint32_t Skew = 0) + : Stream(Stream), E(E), Skew(Skew) {} Iterator begin(bool *HadError = nullptr) const { - return Iterator(*this, E, HadError); + return Iterator(*this, E, Skew, nullptr); } bool valid() const { return Stream.valid(); } + uint32_t skew() const { return Skew; } Iterator end() const { return Iterator(E); } bool empty() const { return Stream.getLength() == 0; } + VarStreamArray<ValueType, Extractor> substream(uint32_t Begin, + uint32_t End) const { + assert(Begin >= Skew); + // We should never cut off the beginning of the stream since it might be + // skewed, meaning the initial bytes are important. + BinaryStreamRef NewStream = Stream.slice(0, End); + return {NewStream, E, Begin}; + } + /// given an offset into the array's underlying stream, return an /// iterator to the record at that offset. This is considered unsafe /// since the behavior is undefined if \p Offset does not refer to the @@ -123,11 +134,17 @@ public: Extractor &getExtractor() { return E; } BinaryStreamRef getUnderlyingStream() const { return Stream; } - void setUnderlyingStream(BinaryStreamRef S) { Stream = S; } + void setUnderlyingStream(BinaryStreamRef S, uint32_t Skew = 0) { + Stream = S; + this->Skew = Skew; + } + + void drop_front() { Skew += begin()->length(); } private: BinaryStreamRef Stream; Extractor E; + uint32_t Skew; }; template <typename ValueType, typename Extractor> @@ -139,10 +156,6 @@ class VarStreamArrayIterator public: VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, - bool *HadError) - : VarStreamArrayIterator(Array, E, 0, HadError) {} - - VarStreamArrayIterator(const ArrayType &Array, const Extractor &E, uint32_t Offset, bool *HadError) : IterRef(Array.Stream.drop_front(Offset)), Extract(E), Array(&Array), AbsOffset(Offset), HadError(HadError) { |