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
p2p
go-yamux
Commits
fad228ec
Unverified
Commit
fad228ec
authored
Feb 17, 2021
by
Marten Seemann
Committed by
GitHub
Feb 17, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #48 from libp2p/fix-buffer-usage
don't reslice byte slices taking from the buffer
parents
c8e9b3ed
380f2826
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
util.go
util.go
+8
-3
No files found.
util.go
View file @
fad228ec
...
@@ -72,6 +72,9 @@ type segmentedBuffer struct {
...
@@ -72,6 +72,9 @@ type segmentedBuffer struct {
pending
uint32
pending
uint32
len
uint32
len
uint32
bm
sync
.
Mutex
bm
sync
.
Mutex
// read position in b[0].
// We must not reslice any of the buffers in b, as we need to put them back into the pool.
readPos
int
b
[][]
byte
b
[][]
byte
}
}
...
@@ -135,13 +138,15 @@ func (s *segmentedBuffer) Read(b []byte) (int, error) {
...
@@ -135,13 +138,15 @@ func (s *segmentedBuffer) Read(b []byte) (int, error) {
if
len
(
s
.
b
)
==
0
{
if
len
(
s
.
b
)
==
0
{
return
0
,
io
.
EOF
return
0
,
io
.
EOF
}
}
n
:=
copy
(
b
,
s
.
b
[
0
])
data
:=
s
.
b
[
0
][
s
.
readPos
:
]
if
n
==
len
(
s
.
b
[
0
])
{
n
:=
copy
(
b
,
data
)
if
n
==
len
(
data
)
{
pool
.
Put
(
s
.
b
[
0
])
pool
.
Put
(
s
.
b
[
0
])
s
.
b
[
0
]
=
nil
s
.
b
[
0
]
=
nil
s
.
b
=
s
.
b
[
1
:
]
s
.
b
=
s
.
b
[
1
:
]
s
.
readPos
=
0
}
else
{
}
else
{
s
.
b
[
0
]
=
s
.
b
[
0
][
n
:
]
s
.
readPos
+=
n
}
}
if
n
>
0
{
if
n
>
0
{
s
.
len
-=
uint32
(
n
)
s
.
len
-=
uint32
(
n
)
...
...
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