Skip to content

Commit

Permalink
fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
purnesh42H committed Oct 24, 2024
1 parent aed354b commit eeb6971
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions mem/buffers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func newBuffer() *buffer {
//
// Note that the backing array of the given data is not copied.
func NewBuffer(data *[]byte, pool BufferPool) Buffer {
// Use the buffer's capacity instead of the length, otherwise buffers may not be reused under certain
// conditions. For example, if a large buffer is acquired from the pool, but fewer bytes than the
// buffering threshold are written to it, the buffer will not be returned to the pool.
// Use the buffer's capacity instead of the length, otherwise buffers may
// not be reused under certain conditions. For example, if a large buffer
// is acquired from the pool, but fewer bytes than the buffering threshold
// are written to it, the buffer will not be returned to the pool.
if pool == nil || IsBelowBufferPoolingThreshold(cap(*data)) {
return (SliceBuffer)(*data)
}
Expand Down
6 changes: 3 additions & 3 deletions mem/buffers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ func (s) TestBuffer_NewBufferHandlesShortBuffers(t *testing.T) {
internal.SetBufferPoolingThresholdForTesting.(func(int))(0)
})

// Make a buffer whose capacity is larger than the pooling threshold, but whose length is less than
// Make a Buffer whose capacity is larger than the pooling threshold, but whose length is less than
// the threshold.
b := make([]byte, threshold/2, threshold*2)
pool := &singleBufferPool{
t: t,
data: &b,
}

// Get a buffer, then free it. If NewBuffer decided that the buffer shouldn't get pooled, Free will
// Get a Buffer, then free it. If NewBuffer decided that the Buffer shouldn't get pooled, Free will
// be a noop and singleBufferPool will not have been updated.
mem.NewBuffer(&b, pool).Free()

if pool.data != nil {
t.Fatalf("buffer not returned to pool")
t.Fatalf("Buffer not returned to pool")
}
}

Expand Down

0 comments on commit eeb6971

Please sign in to comment.