Skip to content

Commit 5f8e2d1

Browse files
committed
Change implementation of ByteReader.isFinished and bytesLeft to a more efficient version (using _offset)
1 parent 3ade64a commit 5f8e2d1

1 file changed

Lines changed: 2 additions & 14 deletions

File tree

Sources/ByteReader.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,12 @@ public class ByteReader {
3434
- Note: It generally means that all bytes have been read.
3535
*/
3636
public var isFinished: Bool {
37-
#if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
38-
return { (data: Data, _offset: Int) -> Bool in
39-
return data.endIndex <= _offset
40-
} (self.data, self._offset)
41-
#else
42-
return self.data.endIndex <= self._offset
43-
#endif
37+
return self.size <= self._offset
4438
}
4539

4640
/// Amount of bytes left to read.
4741
public var bytesLeft: Int {
48-
#if swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0))
49-
return { (data: Data, _offset: Int) -> Int in
50-
return data.endIndex - _offset
51-
} (self.data, self._offset)
52-
#else
53-
return self.data.endIndex - self._offset
54-
#endif
42+
return self.size - self._offset
5543
}
5644

5745
/// Amount of bytes that were already read.

0 commit comments

Comments
 (0)