File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,16 +17,16 @@ public class ByteReader {
1717 /// Offset to the byte in `data` which will be read next.
1818 public var offset : Int {
1919 get {
20- return self . _offset + self . data . startIndex
20+ return self . _offset + self . dataStartIndex
2121 }
2222 set {
23- self . _offset = newValue - self . data . startIndex
23+ self . _offset = newValue - self . dataStartIndex
2424 }
2525 }
2626
2727 var _offset : Int
28-
2928 var ptr : UnsafeBufferPointer < UInt8 >
29+ private let dataStartIndex : Int // For efficient (without access to `data`) implementation of `offset`.
3030
3131 /**
3232 True, if `offset` points at any position after the last byte in `data`.
@@ -55,6 +55,7 @@ public class ByteReader {
5555 self . ptr = data. withUnsafeBytes { ( ptr: UnsafePointer < UInt8 > ) -> UnsafeBufferPointer < UInt8 > in
5656 return UnsafeBufferPointer < UInt8 > ( start: ptr, count: data. count)
5757 }
58+ self . dataStartIndex = data. startIndex
5859 }
5960
6061 /**
You can’t perform that action at this time.
0 commit comments