Skip to content

Commit f19ae57

Browse files
authored
Merge pull request #325 from Basebit/no-skip-if-offset-not-changed
Optimization: BlockReader skip() return nil if size is 0
2 parents 13d9368 + e10812d commit f19ae57

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

internal/transfer/block_reader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ func (br *BlockReader) Read(b []byte) (int, error) {
123123
// isn't connected, or the resulting offset would be out of bounds or too far
124124
// ahead) or the copy failed for some other reason.
125125
func (br *BlockReader) Skip(n int64) error {
126+
if n == 0 {
127+
return nil
128+
}
126129
blockSize := int64(br.Block.GetB().GetNumBytes())
127130
resultingOffset := br.Offset + n
128131

129-
if br.stream == nil || n <= 0 || n > maxSkip || resultingOffset >= blockSize {
132+
if br.stream == nil || n < 0 || n > maxSkip || resultingOffset >= blockSize {
130133
return errors.New("unable to skip")
131134
}
132135

0 commit comments

Comments
 (0)