Skip to content

Commit

Permalink
Merge pull request #325 from Basebit/no-skip-if-offset-not-changed
Browse files Browse the repository at this point in the history
Optimization: BlockReader skip() return nil if size is 0
  • Loading branch information
colinmarc authored Jul 18, 2023
2 parents 13d9368 + e10812d commit f19ae57
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/transfer/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@ func (br *BlockReader) Read(b []byte) (int, error) {
// isn't connected, or the resulting offset would be out of bounds or too far
// ahead) or the copy failed for some other reason.
func (br *BlockReader) Skip(n int64) error {
if n == 0 {
return nil
}
blockSize := int64(br.Block.GetB().GetNumBytes())
resultingOffset := br.Offset + n

if br.stream == nil || n <= 0 || n > maxSkip || resultingOffset >= blockSize {
if br.stream == nil || n < 0 || n > maxSkip || resultingOffset >= blockSize {
return errors.New("unable to skip")
}

Expand Down

0 comments on commit f19ae57

Please sign in to comment.