Skip to content

Commit

Permalink
fix: add race method
Browse files Browse the repository at this point in the history
  • Loading branch information
ppzqh committed Feb 23, 2024
1 parent 0c594e3 commit 442f1dc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nocopy_linkbuffer_race.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,19 @@ func (b *LinkBuffer) Bytes() []byte {
}

// GetBytes will read and fill the slice p as much as possible.
// If p is not passed, return all readable bytes.
func (b *LinkBuffer) GetBytes(p [][]byte) (vs [][]byte) {
b.Lock()
defer b.Unlock()
node, flush := b.read, b.flush
if len(p) == 0 {
n := 0
for ; node != flush; node = node.next {
n++
}
node = b.read
p = make([][]byte, n)
}
var i int
for i = 0; node != flush && i < len(p); node = node.next {
if node.Len() > 0 {
Expand Down

0 comments on commit 442f1dc

Please sign in to comment.