Skip to content

Commit

Permalink
Merge pull request #48 from klauspost/use-copy-for-non-overlapping
Browse files Browse the repository at this point in the history
Use faster copy when not overlapping
  • Loading branch information
nigeltao authored Sep 4, 2019
2 parents 5610373 + efb0d86 commit c9879f9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions decode_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ func decode(dst, src []byte) int {
if offset <= 0 || d < offset || length > len(dst)-d {
return decodeErrCodeCorrupt
}
// Copy from an earlier sub-slice of dst to a later sub-slice. Unlike
// the built-in copy function, this byte-by-byte copy always runs
// Copy from an earlier sub-slice of dst to a later sub-slice.
// If no overlap, use the built-in copy:
if offset >= length {
copy(dst[d:d+length], dst[d-offset:])
d += length
continue
}

// Unlike the built-in copy function, this byte-by-byte copy always runs
// forwards, even if the slices overlap. Conceptually, this is:
//
// d += forwardCopy(dst[d:d+length], dst[d-offset:])
Expand Down

0 comments on commit c9879f9

Please sign in to comment.