Commit c10b0781 authored by Steven Allen's avatar Steven Allen

switch to go-buffer-pool

It has a nicer interface and we don't even need the rest of the msgio

Prereq for: https://github.com/libp2p/go-msgio/pull/9
parent b161c870
......@@ -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",
......@@ -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",
......
......@@ -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")
......@@ -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
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment