Skip to content

Commit

Permalink
Merge pull request #446 from potocnyj/amortize-snappy-allocations
Browse files Browse the repository at this point in the history
Amortize allocations in snappyDecode
  • Loading branch information
eapache committed May 8, 2015
2 parents 68beb72 + 7ad8520 commit 440808c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions snappy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ func snappyEncode(src []byte) ([]byte, error) {
func snappyDecode(src []byte) ([]byte, error) {
if bytes.Equal(src[:8], snappyMagic) {
var (
pos = uint32(16)
max = uint32(len(src))
dst []byte
pos = uint32(16)
max = uint32(len(src))
dst = make([]byte, 0, len(src))
chunk []byte
err error
)
for pos < max {
size := binary.BigEndian.Uint32(src[pos : pos+4])
pos = pos + 4
chunk, err := snappy.Decode(nil, src[pos:pos+size])

chunk, err = snappy.Decode(chunk, src[pos:pos+size])
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 440808c

Please sign in to comment.