Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
aafbe65a
Commit
aafbe65a
authored
Dec 19, 2017
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't waste 256KiB buffers on small chunks.
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
parent
ce22b83f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
10 deletions
+22
-10
importer/chunk/splitting.go
importer/chunk/splitting.go
+16
-10
package.json
package.json
+6
-0
No files found.
importer/chunk/splitting.go
View file @
aafbe65a
...
...
@@ -5,6 +5,7 @@ import (
"io"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
mpool
"gx/ipfs/QmWBug6eBS7AxRdCDVuSY5CnSit7cS2XnPFYJWqWDumhCG/go-msgio/mpool"
)
var
log
=
logging
.
Logger
(
"chunk"
)
...
...
@@ -51,14 +52,14 @@ func Chan(s Splitter) (<-chan []byte, <-chan error) {
type
sizeSplitterv2
struct
{
r
io
.
Reader
size
int
64
size
u
int
32
err
error
}
func
NewSizeSplitter
(
r
io
.
Reader
,
size
int64
)
Splitter
{
return
&
sizeSplitterv2
{
r
:
r
,
size
:
size
,
size
:
uint32
(
size
)
,
}
}
...
...
@@ -66,17 +67,22 @@ func (ss *sizeSplitterv2) NextBytes() ([]byte, error) {
if
ss
.
err
!=
nil
{
return
nil
,
ss
.
err
}
buf
:=
make
([]
byte
,
ss
.
size
)
n
,
err
:=
io
.
ReadFull
(
ss
.
r
,
buf
)
if
err
==
io
.
ErrUnexpectedEOF
{
full
:=
mpool
.
ByteSlicePool
.
Get
(
ss
.
size
)
.
([]
byte
)[
:
ss
.
size
]
n
,
err
:=
io
.
ReadFull
(
ss
.
r
,
full
)
switch
err
{
case
io
.
ErrUnexpectedEOF
:
ss
.
err
=
io
.
EOF
err
=
nil
}
if
err
!=
nil
{
small
:=
make
([]
byte
,
n
)
copy
(
small
,
full
)
mpool
.
ByteSlicePool
.
Put
(
ss
.
size
,
full
)
return
small
,
nil
case
nil
:
return
full
,
nil
default
:
mpool
.
ByteSlicePool
.
Put
(
ss
.
size
,
full
)
return
nil
,
err
}
return
buf
[
:
n
],
nil
}
func
(
ss
*
sizeSplitterv2
)
Reader
()
io
.
Reader
{
...
...
package.json
View file @
aafbe65a
...
...
@@ -509,6 +509,12 @@
"hash"
:
"QmYmhgAcvmDGXct1qBvc1kz9BxQSit1XBrTeiGZp2FvRyn"
,
"name"
:
"go-libp2p-blankhost"
,
"version"
:
"0.2.3"
},
{
"author"
:
"jbenet"
,
"hash"
:
"QmWBug6eBS7AxRdCDVuSY5CnSit7cS2XnPFYJWqWDumhCG"
,
"name"
:
"go-msgio"
,
"version"
:
"0.0.3"
}
],
"gxVersion"
:
"0.10.0"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment