Skip to content

Commit

Permalink
fix: nocopy read add cap restraint
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Jun 20, 2024
1 parent 2c16b97 commit 2425197
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nocopy_linkbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ func (b *UnsafeLinkBuffer) readBinary(n int) (p []byte) {
// for example, if user's codec need to decode 10 strings and each have 100 bytes, here could help the codec
// no need to malloc 10 times and the string slice could have the compact memory allocation.
if b.read.getMode(nocopyReadMask) {
return b.read.Next(n)
return b.read.Next(n)[:n:n]
}
if n >= minReuseBytes && cap(b.read.buf) <= block32k {
b.read.setMode(nocopyReadMask, true)
return b.read.Next(n)
return b.read.Next(n)[:n:n]
}
}
// if the underlying buffer too large, we shouldn't use no-copy mode
Expand Down

0 comments on commit 2425197

Please sign in to comment.