llvm.org GIT mirror llvm / bb47acc
[Support] Provide unsafe random access for VarStreamArray. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301716 91177308-0d34-0410-b5e6-96231b3b80d8 Zachary Turner 3 years ago
1 changed file(s) with 20 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
9292 : Stream(Other.Stream), Context(Other.Context) {}
9393
9494 Iterator begin(bool *HadError = nullptr) const {
95 if (empty())
96 return end();
97
9598 return Iterator(*this, Context, HadError);
9699 }
97100
98101 Iterator end() const { return Iterator(); }
99102
103 bool empty() const { return Stream.getLength() == 0; }
104
105 /// \brief given an offset into the array's underlying stream, return an
106 /// iterator to the record at that offset. This is considered unsafe
107 /// since the behavior is undefined if \p Offset does not refer to the
108 /// beginning of a valid record.
109 Iterator at(uint32_t Offset) const {
110 return Iterator(*this, Context, Stream.drop_front(Offset), nullptr);
111 }
112
100113 BinaryStreamRef getUnderlyingStream() const { return Stream; }
101 void setUnderlyingStream(BinaryStreamRef Stream) { this->Stream = Stream; }
102114
103115 private:
104116 BinaryStreamRef Stream;
116128
117129 public:
118130 VarStreamArrayIterator(const ArrayType &Array, ContextType *Context,
119 bool *HadError = nullptr)
120 : IterRef(Array.Stream), Context(Context), Array(&Array),
121 HadError(HadError) {
131 BinaryStreamRef Stream, bool *HadError = nullptr)
132 : IterRef(Stream), Context(Context), Array(&Array), HadError(HadError) {
122133 if (IterRef.getLength() == 0)
123134 moveToEnd();
124135 else {
129140 }
130141 }
131142 }
143
144 VarStreamArrayIterator(const ArrayType &Array, ContextType *Context,
145 bool *HadError = nullptr)
146 : VarStreamArrayIterator(Array, Context, Array.Stream, HadError) {}
147
132148 VarStreamArrayIterator() = default;
133149 ~VarStreamArrayIterator() = default;
134150