OSDN Git Service

[StreamArray] Pipe the Offset through the constructor.
authorZachary Turner <zturner@google.com>
Fri, 5 May 2017 21:15:31 +0000 (21:15 +0000)
committerZachary Turner <zturner@google.com>
Fri, 5 May 2017 21:15:31 +0000 (21:15 +0000)
When randomly accessing an element by offset, we weren't passing
the offset through so if you called .offset() it would return a
value of 0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302292 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/BinaryStreamArray.h

index b25c03a..b5d5639 100644 (file)
@@ -64,8 +64,8 @@ class VarStreamArrayIterator
 public:
   VarStreamArrayIterator() = default;
   VarStreamArrayIterator(const ArrayType &Array, const WrappedCtx &Ctx,
-                         BinaryStreamRef Stream, bool *HadError = nullptr)
-      : IterRef(Stream), Ctx(&Ctx), Array(&Array), HadError(HadError) {
+                         BinaryStreamRef Stream, bool *HadError = nullptr, uint32_t Offset = 0)
+      : IterRef(Stream), Ctx(&Ctx), Array(&Array), HadError(HadError), AbsOffset(Offset) {
     if (IterRef.getLength() == 0)
       moveToEnd();
     else {
@@ -238,7 +238,7 @@ public:
   /// since the behavior is undefined if \p Offset does not refer to the
   /// beginning of a valid record.
   Iterator at(uint32_t Offset) const {
-    return Iterator(*this, Ctx, Stream.drop_front(Offset), nullptr);
+    return Iterator(*this, Ctx, Stream.drop_front(Offset), nullptr, Offset);
   }
 
   BinaryStreamRef getUnderlyingStream() const { return Stream; }