Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

switch to go-buffer-pool #8

Merged
merged 1 commit into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
"name": "go-log",
"version": "1.5.7"
},
{
"author": "jbenet",
"hash": "QmWBug6eBS7AxRdCDVuSY5CnSit7cS2XnPFYJWqWDumhCG",
"name": "go-msgio",
"version": "0.0.3"
},
{
"author": "whyrusleeping",
"hash": "QmZooytqEoUwQjv7KzH4d3xyJnyvD3AWJaCDMYt5pbCtua",
Expand All @@ -35,6 +29,12 @@
"hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM",
"name": "go-block-format",
"version": "0.2.0"
},
{
"author": "Stebalien",
"hash": "QmUQy76yspPa3fRyY3GzXFTg9n8JVwFru6ue3KFRt4MeTw",
"name": "go-buffer-pool",
"version": "0.1.1"
}
],
"gxVersion": "0.12.1",
Expand Down
8 changes: 4 additions & 4 deletions splitting.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"

logging "github.com/ipfs/go-log"
mpool "github.com/libp2p/go-msgio/mpool"
pool "github.com/libp2p/go-buffer-pool"
)

var log = logging.Logger("chunk")
Expand Down Expand Up @@ -82,19 +82,19 @@ func (ss *sizeSplitterv2) NextBytes() ([]byte, error) {
return nil, ss.err
}

full := mpool.ByteSlicePool.Get(ss.size).([]byte)[:ss.size]
full := pool.Get(int(ss.size))
n, err := io.ReadFull(ss.r, full)
switch err {
case io.ErrUnexpectedEOF:
ss.err = io.EOF
small := make([]byte, n)
copy(small, full)
mpool.ByteSlicePool.Put(ss.size, full)
pool.Put(full)
return small, nil
case nil:
return full, nil
default:
mpool.ByteSlicePool.Put(ss.size, full)
pool.Put(full)
return nil, err
}
}
Expand Down