diff options
author | Zachary Turner <zturner@google.com> | 2017-11-27 18:48:37 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-11-27 18:48:37 +0000 |
commit | 96c6985b5327845be772c2bc13567c2967969cc7 (patch) | |
tree | 630b1fba2331a97d751864515dfa76eb6f168d15 /llvm/lib/Support/BinaryStreamRef.cpp | |
parent | ec6e21427275ce1cdb2580aaa4167b143aab049c (diff) | |
download | bcm5719-llvm-96c6985b5327845be772c2bc13567c2967969cc7.tar.gz bcm5719-llvm-96c6985b5327845be772c2bc13567c2967969cc7.zip |
[BinaryStream] Support growable streams.
The existing library assumed that a stream's length would never
change. This makes some things simpler, but it's not flexible
enough for what we need, especially for writable streams where
what you really want is for each call to write to actually append.
llvm-svn: 319070
Diffstat (limited to 'llvm/lib/Support/BinaryStreamRef.cpp')
-rw-r--r-- | llvm/lib/Support/BinaryStreamRef.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/lib/Support/BinaryStreamRef.cpp b/llvm/lib/Support/BinaryStreamRef.cpp index 70ee156f19f..60a03fe9930 100644 --- a/llvm/lib/Support/BinaryStreamRef.cpp +++ b/llvm/lib/Support/BinaryStreamRef.cpp @@ -66,9 +66,9 @@ private: } BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream) - : BinaryStreamRef(Stream, 0, Stream.getLength()) {} + : BinaryStreamRefBase(Stream) {} BinaryStreamRef::BinaryStreamRef(BinaryStream &Stream, uint32_t Offset, - uint32_t Length) + Optional<uint32_t> Length) : BinaryStreamRefBase(Stream, Offset, Length) {} BinaryStreamRef::BinaryStreamRef(ArrayRef<uint8_t> Data, endianness Endian) : BinaryStreamRefBase(std::make_shared<ArrayRefImpl>(Data, Endian), 0, @@ -79,14 +79,14 @@ BinaryStreamRef::BinaryStreamRef(StringRef Data, endianness Endian) Error BinaryStreamRef::readBytes(uint32_t Offset, uint32_t Size, ArrayRef<uint8_t> &Buffer) const { - if (auto EC = checkOffset(Offset, Size)) + if (auto EC = checkOffsetForRead(Offset, Size)) return EC; return BorrowedImpl->readBytes(ViewOffset + Offset, Size, Buffer); } Error BinaryStreamRef::readLongestContiguousChunk( uint32_t Offset, ArrayRef<uint8_t> &Buffer) const { - if (auto EC = checkOffset(Offset, 1)) + if (auto EC = checkOffsetForRead(Offset, 1)) return EC; if (auto EC = @@ -95,18 +95,18 @@ Error BinaryStreamRef::readLongestContiguousChunk( // This StreamRef might refer to a smaller window over a larger stream. In // that case we will have read out more bytes than we should return, because // we should not read past the end of the current view. - uint32_t MaxLength = Length - Offset; + uint32_t MaxLength = getLength() - Offset; if (Buffer.size() > MaxLength) Buffer = Buffer.slice(0, MaxLength); return Error::success(); } WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream) - : WritableBinaryStreamRef(Stream, 0, Stream.getLength()) {} + : BinaryStreamRefBase(Stream) {} WritableBinaryStreamRef::WritableBinaryStreamRef(WritableBinaryStream &Stream, uint32_t Offset, - uint32_t Length) + Optional<uint32_t> Length) : BinaryStreamRefBase(Stream, Offset, Length) {} WritableBinaryStreamRef::WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data, @@ -117,7 +117,7 @@ WritableBinaryStreamRef::WritableBinaryStreamRef(MutableArrayRef<uint8_t> Data, Error WritableBinaryStreamRef::writeBytes(uint32_t Offset, ArrayRef<uint8_t> Data) const { - if (auto EC = checkOffset(Offset, Data.size())) + if (auto EC = checkOffsetForWrite(Offset, Data.size())) return EC; return BorrowedImpl->writeBytes(ViewOffset + Offset, Data); |