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 @@ ...@@ -12,12 +12,6 @@
"name": "go-log", "name": "go-log",
"version": "1.5.7" "version": "1.5.7"
}, },
{
"author": "jbenet",
"hash": "QmWBug6eBS7AxRdCDVuSY5CnSit7cS2XnPFYJWqWDumhCG",
"name": "go-msgio",
"version": "0.0.3"
},
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmZooytqEoUwQjv7KzH4d3xyJnyvD3AWJaCDMYt5pbCtua", "hash": "QmZooytqEoUwQjv7KzH4d3xyJnyvD3AWJaCDMYt5pbCtua",
...@@ -35,6 +29,12 @@ ...@@ -35,6 +29,12 @@
"hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM", "hash": "QmRcHuYzAyswytBuMF78rj3LTChYszomRFXNg4685ZN1WM",
"name": "go-block-format", "name": "go-block-format",
"version": "0.2.0" "version": "0.2.0"
},
{
"author": "Stebalien",
"hash": "QmUQy76yspPa3fRyY3GzXFTg9n8JVwFru6ue3KFRt4MeTw",
"name": "go-buffer-pool",
"version": "0.1.1"
} }
], ],
"gxVersion": "0.12.1", "gxVersion": "0.12.1",
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"io" "io"
logging "github.com/ipfs/go-log" 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") var log = logging.Logger("chunk")
...@@ -82,19 +82,19 @@ func (ss *sizeSplitterv2) NextBytes() ([]byte, error) { ...@@ -82,19 +82,19 @@ func (ss *sizeSplitterv2) NextBytes() ([]byte, error) {
return nil, ss.err 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) n, err := io.ReadFull(ss.r, full)
switch err { switch err {
case io.ErrUnexpectedEOF: case io.ErrUnexpectedEOF:
ss.err = io.EOF ss.err = io.EOF
small := make([]byte, n) small := make([]byte, n)
copy(small, full) copy(small, full)
mpool.ByteSlicePool.Put(ss.size, full) pool.Put(full)
return small, nil return small, nil
case nil: case nil:
return full, nil return full, nil
default: default:
mpool.ByteSlicePool.Put(ss.size, full) pool.Put(full)
return nil, err 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